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

标签 android jenkins gradle calabash

我有一个简单的测试android项目,可以在以我自己身份登录的DOS shell 中使用“。\ gradlew calabashDebug”进行精细测试。但是,当我在Continuous Integration服务器上的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
    

    最佳答案

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

    # 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
    

    关于android - Jenkins android模拟器插件可创建多个虚拟设备,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23296904/

    相关文章:

    ssl - GitLab 的 Jenkins 身份验证失败

    android - 新依赖 React native - gradle clean - 无法解析所有依赖

    java - 通过 Gradle 进行测试时的日志记录

    gradle - Gradle 4+无法解决来自自定义Maven存储库的快照依赖关系

    android - 使用 adb 查找设备蓝牙 MAC 地址

    java - 如何在浮点值膨胀之前将浮点值传递给扩展 LinearLayout 的类?

    php - SonarQube PHP 无代码覆盖率

    android - 如何在 Activity 之外使用 sharedPreferences?

    android - 如何模拟在 android 中弹奏一个钢琴音符?

    jenkins - 中止时如何使用 SIGINT 而不是 SIGTERM 终止 Jenkins 作业中的 psql 进程?