In addition to using Bamboo to create an APK for my Android project, I also wanted to use Bamboo to run JUnit based tests against the Android emulator. After quite a few βtrial and errorβ, first of all, in finding a reliable way to start and stop the Android emulator, this is what I came up with for my Bamboo build plan. See Bamboo is waiting for a script job to complete, although it is running in the background for more reference on why I am using the approach described below.
My Bamboo plan has one step with two tasks. Tasks are performed using two agents that run on the same system. Both jobs start and run in parallel. One job launches the Android emulator using the Android SDK emulator command. Another task waits for the emulator to start, the mobile application to build, runs the tests with the emulator, and then stops the emulator running, using the final task, which is always performed even if the previous task in the build task fails.
The emulator task gets stuck after starting the emulator because it is waiting for the emulation process to complete. When the build job is running, the final task in the build job stops the emulator, which causes the emulator job to end because the emulation process no longer works.
Here is the basic information about the build task:
The first task is a script task that is waiting for the emulator to start. The following is the adb -s command, in which this task will not work if the emulator does not start.
echo "Waiting 60 seconds for the Android emulator to start" sleep 60 echo "See if Emulator is up and running" ${bamboo.ANDROID_HOME}/platform-tools/adb -s emulator-5554 shell getprop dev.bootcomplete
The second and third tasks check the source and create the application using Gradle. The assembly runs JUnit tests against a working emulator.
The fourth task, which is configured as the final task, is a script task that stops the emulator.
echo "Stopping the Android emulator" ${bamboo.ANDROID_HOME}/platform-tools/adb -s emulator-5554 emu kill