1

I have a simple test android project that I can test fine using ".\gradlew calabashDebug" in a DOS shell logged in as myself. However, when I run the project under Jenkins on a Continuous Integration server it fails during calabashDebug task because there are multiple Android Virtual Devices running:

$ C:\AndroidSDK\adt-bundle-windows-x86_64-20140321\adt-bundle-windows-x86_64-20140321\sdk/tools/android.bat list target
[android] Using Android SDK: C:\AndroidSDK\adt-bundle-windows-x86_64-20140321\adt-bundle-windows-x86_64-20140321\sdk
$ C:\AndroidSDK\adt-bundle-windows-x86_64-20140321\adt-bundle-windows-x86_64-20140321\sdk/platform-tools/adb.exe start-server
$ C:\AndroidSDK\adt-bundle-windows-x86_64-20140321\adt-bundle-windows-x86_64-20140321\sdk/tools/emulator.exe -snapshot-list -no-window -avd hudson_en-US_213_800x1280_android-17_x86
[android] Starting Android emulator and creating initial snapshot
[android] Erasing existing emulator data...
$ C:\AndroidSDK\adt-bundle-windows-x86_64-20140321\adt-bundle-windows-x86_64-20140321\sdk/tools/emulator.exe -no-boot-anim -ports 50834,50835 -avd hudson_en-US_213_800x1280_android-17_x86 -no-snapshot-load -no-snapshot-save -wipe-data
* daemon not running. starting it now on port 50836 *
* daemon started successfully *
Failed to create Context 0x3005
emulator: WARNING: Could not initialize OpenglES emulation, using software renderer.
could not get wglGetExtensionsStringARB
could not get wglGetExtensionsStringARB
could not get wglGetExtensionsStringARB
could not get wglGetExtensionsStringARB
could not get wglGetExtensionsStringARB
could not get wglGetExtensionsStringARB
could not get wglGetExtensionsStringARB
could not get wglGetExtensionsStringARB
emulator: warning: opening audio output failed

$ C:\AndroidSDK\adt-bundle-windows-x86_64-20140321\adt-bundle-windows-x86_64-20140321\sdk/platform-tools/adb.exe connect localhost:50835
[android] Waiting for emulator to finish booting...
$ C:\AndroidSDK\adt-bundle-windows-x86_64-20140321\adt-bundle-windows-x86_64-20140321\sdk/platform-tools/adb.exe -s localhost:50835 shell getprop dev.bootcomplete
error: device not found
$ C:\AndroidSDK\adt-bundle-windows-x86_64-20140321\adt-bundle-windows-x86_64-20140321\sdk/platform-tools/adb.exe connect localhost:50835
$ C:\AndroidSDK\adt-bundle-windows-x86_64-20140321\adt-bundle-windows-x86_64-20140321\sdk/platform-tools/adb.exe -s localhost:50835 shell getprop dev.bootcomplete
error: device not found
$ C:\AndroidSDK\adt-bundle-windows-x86_64-20140321\adt-bundle-windows-x86_64-20140321\sdk/platform-tools/adb.exe connect localhost:50835
$ C:\AndroidSDK\adt-bundle-windows-x86_64-20140321\adt-bundle-windows-x86_64-20140321\sdk/platform-tools/adb.exe -s localhost:50835 shell getprop dev.bootcomplete
error: device not found
$ C:\AndroidSDK\adt-bundle-windows-x86_64-20140321\adt-bundle-windows-x86_64-20140321\sdk/platform-tools/adb.exe disconnect localhost:50835
$ C:\AndroidSDK\adt-bundle-windows-x86_64-20140321\adt-bundle-windows-x86_64-20140321\sdk/platform-tools/adb.exe connect localhost:50835
$ C:\AndroidSDK\adt-bundle-windows-x86_64-20140321\adt-bundle-windows-x86_64-20140321\sdk/platform-tools/adb.exe -s localhost:50835 shell getprop dev.bootcomplete
error: device not found
$ C:\AndroidSDK\adt-bundle-windows-x86_64-20140321\adt-bundle-windows-x86_64-20140321\sdk/platform-tools/adb.exe connect localhost:50835
$ C:\AndroidSDK\adt-bundle-windows-x86_64-20140321\adt-bundle-windows-x86_64-20140321\sdk/platform-tools/adb.exe -s localhost:50835 shell getprop dev.bootcomplete
error: device not found
$ C:\AndroidSDK\adt-bundle-windows-x86_64-20140321\adt-bundle-windows-x86_64-20140321\sdk/platform-tools/adb.exe connect localhost:50835
$ C:\AndroidSDK\adt-bundle-windows-x86_64-20140321\adt-bundle-windows-x86_64-20140321\sdk/platform-tools/adb.exe -s localhost:50835 shell getprop dev.bootcomplete
error: device not found
$ C:\AndroidSDK\adt-bundle-windows-x86_64-20140321\adt-bundle-windows-x86_64-20140321\sdk/platform-tools/adb.exe disconnect localhost:50835
$ C:\AndroidSDK\adt-bundle-windows-x86_64-20140321\adt-bundle-windows-x86_64-20140321\sdk/platform-tools/adb.exe connect localhost:50835
$ C:\AndroidSDK\adt-bundle-windows-x86_64-20140321\adt-bundle-windows-x86_64-20140321\sdk/platform-tools/adb.exe -s localhost:50835 shell getprop dev.bootcomplete
error: device not found
$ C:\AndroidSDK\adt-bundle-windows-x86_64-20140321\adt-bundle-windows-x86_64-20140321\sdk/platform-tools/adb.exe connect localhost:50835
$ C:\AndroidSDK\adt-bundle-windows-x86_64-20140321\adt-bundle-windows-x86_64-20140321\sdk/platform-tools/adb.exe -s localhost:50835 shell getprop dev.bootcomplete
error: device not found
$ C:\AndroidSDK\adt-bundle-windows-x86_64-20140321\adt-bundle-windows-x86_64-20140321\sdk/platform-tools/adb.exe connect localhost:50835
$ C:\AndroidSDK\adt-bundle-windows-x86_64-20140321\adt-bundle-windows-x86_64-20140321\sdk/platform-tools/adb.exe -s localhost:50835 shell getprop dev.bootcomplete
$ C:\AndroidSDK\adt-bundle-windows-x86_64-20140321\adt-bundle-windows-x86_64-20140321\sdk/platform-tools/adb.exe disconnect localhost:50835
$ C:\AndroidSDK\adt-bundle-windows-x86_64-20140321\adt-bundle-windows-x86_64-20140321\sdk/platform-tools/adb.exe connect localhost:50835
$ C:\AndroidSDK\adt-bundle-windows-x86_64-20140321\adt-bundle-windows-x86_64-20140321\sdk/platform-tools/adb.exe -s localhost:50835 shell getprop dev.bootcomplete
$ C:\AndroidSDK\adt-bundle-windows-x86_64-20140321\adt-bundle-windows-x86_64-20140321\sdk/platform-tools/adb.exe -s localhost:50835 logcat -v time
$ C:\AndroidSDK\adt-bundle-windows-x86_64-20140321\adt-bundle-windows-x86_64-20140321\sdk/platform-tools/adb.exe connect localhost:50835
[android] Attempting to unlock emulator screen
$ C:\AndroidSDK\adt-bundle-windows-x86_64-20140321\adt-bundle-windows-x86_64-20140321\sdk/platform-tools/adb.exe -s localhost:50835 shell input keyevent 82
$ C:\AndroidSDK\adt-bundle-windows-x86_64-20140321\adt-bundle-windows-x86_64-20140321\sdk/platform-tools/adb.exe -s localhost:50835 shell input keyevent 4
[android] Giving the system some time to settle before creating initial snapshot...
$ C:\AndroidSDK\adt-bundle-windows-x86_64-20140321\adt-bundle-windows-x86_64-20140321\sdk/platform-tools/adb.exe connect localhost:50835
$ C:\AndroidSDK\adt-bundle-windows-x86_64-20140321\adt-bundle-windows-x86_64-20140321\sdk/platform-tools/adb.exe -s localhost:50835 logcat -c
$ C:\AndroidSDK\adt-bundle-windows-x86_64-20140321\adt-bundle-windows-x86_64-20140321\sdk/platform-tools/adb.exe -s localhost:50835 shell log -p v -t Jenkins "Creating snapshot..."
[android] Creating snapshot...
$ C:\AndroidSDK\adt-bundle-windows-x86_64-20140321\adt-bundle-windows-x86_64-20140321\sdk/platform-tools/adb.exe connect localhost:50835
[android] Emulator is ready for use (took 331 seconds)
[Gradle] - Launching build.
[workspace] $ cmd.exe /C '"C:\Users\jenkins\.jenkins\jobs\Toasty\workspace\gradlew.bat calabashDebug && exit %%ERRORLEVEL%%"'
:compileDebugNdk UP-TO-DATE
:preBuild
:preDebugBuild
:checkDebugManifest
:prepareDebugDependencies
:compileDebugAidl UP-TO-DATE
:compileDebugRenderscript UP-TO-DATE
:generateDebugBuildConfig UP-TO-DATE
:mergeDebugAssets UP-TO-DATE
:generateDebugResValues UP-TO-DATE
:generateDebugResources UP-TO-DATE
:mergeDebugResources UP-TO-DATE
:processDebugManifest UP-TO-DATE
:processDebugResources UP-TO-DATE
:generateDebugSources UP-TO-DATE
:compileDebugJava UP-TO-DATE
:preDexDebug UP-TO-DATE
:dexDebug UP-TO-DATE
:processDebugJavaRes UP-TO-DATE
:validateDebugSigning
:packageDebug UP-TO-DATE
:assembleDebug UP-TO-DATE
:calabashDebug
2014-04-25 08:24:36 - JDK found on PATH.
2014-04-25 08:24:36 - JDK found at: C:\Program Files\Java\jdk1.8.0
2014-04-25 08:24:36 - Android SDK found at: C:\AndroidSDK\adt-bundle-windows-x86_64-20140321\adt-bundle-windows-x86_64-20140321\sdk
2014-04-25 08:24:37 - c:/Ruby193/bin/ruby.exe -S cucumber --format html --out C:\Users\jenkins\.jenkins\jobs\Toasty\workspace\build\reports\calabash\Debug\report.html -v MAIN_ACTIVITY=com.example.toasty.MainActivity APP_PATH="C:/Users/jenkins/.jenkins/jobs/Toasty/workspace/build/apk/workspace-debug-unaligned.apk" TEST_APP_PATH="test_servers/3ad00ebd6d3858b2667e3d4fef0e19e7_0.4.21.apk"
*** WARNING: You must use ANSICON 1.31 or higher (https://github.com/adoxa/ansicon/) to get coloured output on Windows
Code:
  * features/support/env.rb
  * features/support/app_installation_hooks.rb
  * features/support/app_life_cycle_hooks.rb
  * features/support/hooks.rb
  * features/step_definitions/calabash_steps.rb

Features:
  * features/my_first.feature
Parsing feature files took 0m0.009s

2014-04-25 08:24:38 - First scenario in feature - reinstalling apps
2014-04-25 08:24:38 - connected_devices: ["emulator-5556", "emulator-50834", "localhost:50835"]
2014-04-25 08:24:38 - connected_devices: ["emulator-5556", "emulator-50834", "localhost:50835"]
2014-04-25 08:24:38 - connected_devices: ["emulator-5556", "emulator-50834", "localhost:50835"]
:calabashDebug FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':calabashDebug'.
> Process 'command 'cmd'' finished with non-zero exit value 1

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

I am using the Jenkins Android Emulator Plugin to start an android virtual device using the following configuration:

  • Run emulator with properties
  • Show emulator window
  • Use emulator snapshots

Why are there mutiple devices ("emulator-5556", "emulator-50834", "localhost:50835") started by the emulator plugin?

FWIW, I am unable to get the Jenkins Android Emulator Pluginb to work on Centos 6 either. So I am giving up on this promising looking plugin for now.

$ /var/lib/jenkins/tools/android-sdk/platform-tools/adb connect localhost:41704
$ /var/lib/jenkins/tools/android-sdk/platform-tools/adb -s localhost:41704 shell getprop dev.bootcomplete
error: device offline
$ /var/lib/jenkins/tools/android-sdk/platform-tools/adb disconnect localhost:41704
$ /var/lib/jenkins/tools/android-sdk/platform-tools/adb connect localhost:41704
[android] Timed-out after waiting 180 seconds for emulator
$ /var/lib/jenkins/tools/android-sdk/platform-tools/adb disconnect localhost:41704
[android] Stopping Android emulator
Carl Manaster
  • 39,912
  • 17
  • 102
  • 155
Farrukh Najmi
  • 5,055
  • 3
  • 35
  • 54
  • After note: It is possible that this issue http://stackoverflow.com/questions/13381460/why-is-jenkins-android-emulator-plugin-recreating-my-emulator-snapshots-in-every is related to my issue. Since original post I tried specifying emulator-arm as emulator executable. This did not change the problem signature. – Farrukh Najmi Apr 25 '14 at 15:28
  • Then I cloned latest bits from android-emulator-plugin project, built 2.11-SNAPSHOT and ran with it. The problem signature did not change. – Farrukh Najmi Apr 25 '14 at 16:02
  • I have come to the conclusion that setting up Jenkins on windows for Android projects has problems with starting the Android Virtual Device. The Jenkins Android Emulator Plugin starts too many and there is no way to setup starting an AVD on system boot that I can figure out. So I am giving up on this and setting up Jenkins on Linux. – Farrukh Najmi Apr 29 '14 at 12:25
  • I have updated main post with issues I see even on Linux. I am giving up on Jenkins Android Emulator Plugin until someone helps figure these issues out. – Farrukh Najmi Apr 29 '14 at 23:14
  • 1
    AFAIK, it started when SDK tools 22.6.1 was released, i.e. it's not explicitly a problem from the plugin. But the plugin should be soon patched to fix it. See https://issues.jenkins-ci.org/browse/JENKINS-22334 for info. – Christopher Orr May 09 '14 at 19:51

1 Answers1

0

Yes this happens sometimes. I had to manually write a script that handled the opening and closing of emulator for every job.

# record screen
recordScreen=true

# kill emulator or not
qemu=`netstat -pltn | grep :5554 | awk '{print $7}' | head -1`
IFS='/' read -ra PIDS_EMU <<< "$qemu"
emu_pid=${PIDS_EMU[0]}
if [ -z "$emu_pid" ]
then
      echo "No pending emulator" 
else
      kill -9 $emu_pid
fi

# open emulator
/opt/android-sdk/emulator/./emulator -skin 720x1280 -prop persist.sys.language=en-prop persist.sys.country=US -avd hudson_en-US_320_720x1280_Google_Inc._Google_APIs_27_x86_qa_testing_avd_27 -no-window &

The path to the emulator might be different. recordScreen is a variable used from jenkins parameter in job

# close emulator or not
qemu=`netstat -pltn | grep :5554 | awk '{print $7}' | head -1`
IFS='/' read -ra PIDS_EMU <<< "$qemu"
emu_pid=${PIDS_EMU[0]}
if [ -z "$emu_pid" ]
then
      echo "No pending emulator" 
else
      kill -9 $emu_pid
fi
Mohit Singh
  • 177
  • 2
  • 9