Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android emulator command line will not terminate

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.

like image 274
Son Nguyen Avatar asked Mar 07 '23 21:03

Son Nguyen


1 Answers

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
like image 165
that other guy Avatar answered Mar 10 '23 11:03

that other guy