I have a simple shell script like this (running on Mac):
/Users/abcdef/Library/Android/sdk/tools/emulator -avd Pixel_API_23
./gradlew assembleDebug assembleAndroidTest
fastlane screengrab
The problem is after running the first line, it starts an emulator just fine, but the command stalls, it will not finish so the next lines cannot be executed. I tried to force-stop it, but that doesn't even work. If I close that terminal, start a new one, and run the script again, the first command will exit (the emulator is already running) and the rest will be executed.
I want to automate screenshot a series of devices, so I want to use a single shell script.
The emulator command finishes when the emulator exits.
If the emulator doesn't exit, the emulator command doesn't finish.
You instead want to continue without waiting for the command to finish, which you can do by running it in the background:
/Users/abcdef/Library/Android/sdk/tools/emulator -avd Pixel_API_23 &
However, the script now continues immediately, so the emulator has not finished loading by the time you run the next lines. You need to wait until the emulator is ready to accept commands.
One simple way of doing that would be to poll using adb
:
until adb shell true; do sleep 1; done
So all in all:
/Users/abcdef/Library/Android/sdk/tools/emulator -avd Pixel_API_23 &
until adb shell true; do sleep 1; done
./gradlew assembleDebug assembleAndroidTest
fastlane screengrab
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With