Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wait for Android emulator to be running before next shell command?

Tags:

I started an Android emulator using the following shell command:

emulator -avd TEST_AVD 

The emulator starts just fine, but the shell script never finishes executing. It just hangs there even after the emulator has completed startup. I have tried with a number of other arguments that I could find, but nothing could quite do what I want it to. How do I know, or stop the shell command, when the emulator is ready to go?

I am setting up our Jenkins CI to use a Jenkinsfile to start the emulator, and then run a series of gradle commands. In short, I'd like to do this:

sh "emulator -avd TEST_AVD" sh "./gradlew clean test spoon" 

However, I don't want to run the gradle tasks until the emulator has finished startup, and I can't figure out how to do that in the terminal.

like image 221
AdamMc331 Avatar asked Dec 14 '16 20:12

AdamMc331


People also ask

What is ADB wait for device?

wait-for-device can be specified after adb to ensure that the command will run once the device is connected. -s can be used to send the commands to a specific device when multiple are connected.

How do I run an emulator from command prompt?

Use the emulator command to start the emulator, as an alternative to running your project or starting it through the AVD Manager. Here's the basic command-line syntax for starting a virtual device from a terminal prompt: emulator -avd avd_name [ {- option [ value ]} … ]

How do I fix an error opening emulator?

If the emulator fails to launch due to the error vulkan-1. dll cannot be found , you probably need to update the emulator. To update the emulator in Android Studio, go to Tools > SDK Manager and install the latest stable version of Android platform.


1 Answers

If you want to do something after you start the emulator you should start it in the background

emulator -avd TEST_AVD & adb wait-for-device # other stuff here 

adb can wait for a device over a transport to be in a particular state

  adb wait-for[-<transport>]-<state>                                - wait for device to be in the given state:                                  device, recovery, sideload, or bootloader                                  Transport is: usb, local or any [default=any] 
like image 99
Diego Torres Milano Avatar answered Sep 27 '22 19:09

Diego Torres Milano