Jenkins android模拟器插件创建多个虚拟设备

时间:2014-04-25 15:14:09

标签: android jenkins gradle calabash

我有一个简单的测试android项目,我可以使用“。\ gradlew calabashDebug”在我自己登录的DOS shell中测试。但是,当我在持续集成服务器上的Jenkins下运行项目时,它在calabashDebug任务期间失败,因为有多个Android虚拟设备正在运行:

$ 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

我使用Jenkins Android Emulator Plugin使用以下配置启动Android虚拟设备:

  • 使用属性
  • 运行模拟器
  • 显示模拟器窗口
  • 使用模拟器快照

为什么模拟器插件启动了多个设备(“emulator-5556”,“emulator-50834”,“localhost:50835”)?

FWIW,我无法让Jenkins Android Emulator Pluginb在Centos 6上运行。所以我现在放弃这个有前途的插件。

$ /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

1 个答案:

答案 0 :(得分:0)

是的,有时会发生这种情况。我必须手动编写一个脚本来处理每个作业的模拟器的打开和关闭。

# 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 &

仿真器的路径可能不同。 recordScreen是作业中的jenkins参数使用的变量

# 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