Executing an external tool before the run
Answered
Hi
I'm trying to run the Android emulator before the `run-android` command from react-native.
I've searched a bit, but all the answers I found were about creating the external tool (which I already have).
To make it simple, I've setup the emulator like this https://i.snag.gy/0XYpdu.jpg and running the command work as expected
> `/Users/ml/Library/Android/sdk/tools/emulator -avd Nexus_5X_API_24`
When I hit the run button the external tool doesn't seem to start, that is setup like this https://i.snag.gy/aNQhLI.jpg.
For iOS, since the emulator starts from the react native command, it works like a charm.
Any idea what might be wrong?
Thanks
Please sign in to leave a comment.
Does the external tool work by itself if you start it from Tools menu?
Couldn't find how in the tools menu https://i.snag.gy/zXwYMT.jpg
This https://confluence.jetbrains.com/display/PhpStorm/Running+External+Tools+in+PhpStorm#RunningExternalToolsinPhpStorm-3.WorkwiththeExternalTool wasn't that helpful also.
Can you please tell me how?
Works exactly as described in the document you have linked.
You forgot to tick the options to show your tool in the menu:
You're right, after adding that it shows in the menu
And the Android emulator works if I manually trigger it through the menu.
Are there any errors in idea.log when you start this configuration?
>When I hit the run button the external tool doesn't seem to start
As far as I have checked, external tools added to React Native run configuration do start correctly. Why do you think that the emulator doesn't start? Can you see any errors? Did you check if the emulator is available among running processes?
Note that tools launched from run configuration need to return an exit code - the main process is waiting for return code to start. This is the way 'before launch' is designed - it's supposed to be used to run some sort of pre-processing before running the main process. So, react-native process won't start: it will be blocked until the emulator is terminated. So, adding emulator to the 'before launch' section of your run configuration is not the right way to go.
One could use an .sh script as an external tool that will spawn an emulator detached (using &), then wait several seconds until the emulator is started and then return the zero exit code. This way external tool will not block the execution of the run configuration.
> Are there any errors in idea.log when you start this configuration?
| FAILURE: Build failed with an exception.
| * What went wrong:
| Execution failed for task ':app:installDebug'.
| > com.android.builder.testing.api.DeviceException: No connected devices!
> As far as I have checked, external tools added to React Native run configuration do start correctly.
The Packager is running as expected, but by default it doesn't start the emulator on its own, that's what I am trying to add.
> Why do you think that the emulator doesn't start?
The emulator will pop up another window with the expected mobile
> Can you see any errors?
Only the mentioned above
> Did you check if the emulator is available among running processes?
Yes, the emulator is not running at all.
> Note that tools launched from run configuration need to return an exit code
Ok, this will be an impediment because the command needs to keep running in parallel, I'll try Serge solution of the script.
Although that means that the external tool is not being called, otherwise the react-native run will not even be called
For me, that solution will probably do but doesn't explain why the tool doesn't run.
Thanks both
The sequence is as follows:
1. build
2. before launch task
3. launch
Since build fails, the configuration doesn't even start.
I though the external tool wound start before, at least that was the idea