Travis CI Android测试:没有连接设备

Ter*_*rry 30 continuous-integration android travis-ci

我正在尝试为Android设置Travis.到目前为止,运行构建似乎工作,但是当涉及到测试时,它抱怨"没有连接的设备!"

:app:connectedAndroidTestDebug FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:connectedAndroidTestDebug'.
> com.android.builder.testing.api.DeviceException: java.lang.RuntimeException: 
    No connected devices!
Run Code Online (Sandbox Code Playgroud)

这是我的.travis.yml,根据我的理解,我正在为测试创建和启动模拟器,就像文档所说的那样.

language: android
android:
  components:
    # Uncomment the lines below if you want to
    # use the latest revision of Android SDK Tools
    # - platform-tools
    # - tools

    # The BuildTools version used by your project
    - build-tools-22.0.1

    # The SDK version used to compile your project
    - android-22

    # Additional components
    - extra-google-google_play_services
    - extra-google-m2repository
    - extra-android-m2repository
    # - addon-google_apis-google-19
    # - add-on
    # - extra

    # Specify at least one system image,
    # if you need to run emulator(s) during your tests
    - sys-img-armeabi-v7a-android-22
    # - sys-img-x86-android-17

  licenses:
    - 'android-sdk-license-.+'

  # Emulator Management: Create, Start and Wait
  before_script:
    - echo no | android create avd --force -n test -t android-22 --abi armeabi-v7a
    - emulator -avd test -no-skin -no-audio -no-window &
    - android-wait-for-emulator
    - adb shell input keyevent 82 &
Run Code Online (Sandbox Code Playgroud)

你能告诉我我做错了什么以及如何解决它?

J-B*_*ssi 13

不幸的是我不能发表评论,因为我只想完成DominicJodoin的回答.ADB_INSTALL_TIMEOUT正如DominicJodoin所说,正确的缩进和更长的时间是必要的.

在我看来你的模拟器正在运行但尚未准备好安装apk.随着- adb wait-for-device你等到连接的设备.根据文档,这意味着:

请注意,此命令不会导致adb等待整个系统完全引导.因此,您不应将其添加到需要完全引导系统的其他命令.

请尝试使用- android-wait-for-emulatortravis.yml 替换此行.

Travis.yml

language: android
jdk: oraclejdk7
cache:
  directories:
   - node_modules
sudo: false

android:
  components:
   # Uncomment the lines below if you want to
    # use the latest revision of Android SDK Tools
    # - platform-tools
    # - tools

    # The BuildTools version used by your project
    - build-tools-22.0.1

    # The SDK version used to compile your project
    - android-22

    # Additional components
    - extra-google-google_play_services
    - extra-google-m2repository
    - extra-android-m2repository
    # - addon-google_apis-google-19
    # - add-on
    # - extra

    # Specify at least one system image,
    # if you need to run emulator(s) during your tests
    - sys-img-armeabi-v7a-android-21
    # - sys-img-x86-android-17

  licenses:
   - 'android-sdk-license-.+'

env:
  global:
   # install timeout in minutes (2 minutes by default)
    - ADB_INSTALL_TIMEOUT=8

# Emulator Management: Create, Start and Wait
before_script:
  - echo no | android create avd --force -n test -t android-21 --abi armeabi-v7a
  - emulator -avd test -no-skin -no-audio -no-window &
  - android-wait-for-emulator
  - adb shell input keyevent 82 &

script:
  - android list target
  - ./gradlew connectedAndroidTest
Run Code Online (Sandbox Code Playgroud)

编辑:修复了上面YAML代码段中的缩进.

  • 您好,我不是这个主题的专家,我不知道如何在travis上扩展内存.在我的构建中,我还使用此选项`-PdisablePreDex"`运行gradle构建.如上所述[here](http://tools.android.com/tech-docs/new-build-system/tips#TOC-Improving-构建服务器性能.)这提高了构建服务器的性能.据我所知,预先运行需要内存的许多进程.如果运行增量构建,则可以从预先处理中受益,而travis构建服务器则不然还要更改给定链接中所述的build.gradle. (2认同)

Dom*_*oin 8

我认为您的问题是sys-img-armeabi-v7a-android-22Travis CI上还没有图片.

实际上,如果您在Travis CI上运行以下命令:android list target,输出android-22显示noTag/ABIs : no ABIs.

我建议你sys-img-armeabi-v7a-android-21在此期间尝试运行测试.

您可以查看一个带有单元测试的Android项目示例,我已经分叉并使用您的组件成功运行,但sys-img-armeabi-v7a-android-21在Travis CI上有图像:

希望这可以帮助!

编辑: android-22图片应该很快就会在Travis CI上提供.请参阅以下拉取请求.