运行仪器测试离子Gitlab CI时出现不兼容的AVD错误

Posted

技术标签:

【中文标题】运行仪器测试离子Gitlab CI时出现不兼容的AVD错误【英文标题】:Getting incompatible AVD error while running instrumentation test ion Gitlab CI 【发布时间】:2017-08-31 21:53:37 【问题描述】:

每当我尝试为我的 android 项目运行仪器测试时,我都会遇到以下错误:

Skipping device 'test(AVD)' for 'app:': Unknown API Level

 > : No compatible devices connected.[TestRunner] FAILED 
Found 1 connected device(s), 0 of which were compatible.
:app:connectedDebugAndroidTest FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:connectedDebugAndroidTest'.
> There were failing tests. See the report at: file:///builds/antitheft/anti-theft-screen-lock/app/build/reports/androidTests/connected/index.html

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

BUILD FAILED

Total time: 2 mins 45.163 secs
ERROR: Job failed: exit code 1

我正在使用共享跑步者。我的目标 API 是 25,我正在尝试在 API 22 上运行 AVD。

这是我的 gitlab-ci.yml 文件:

image: openjdk:8-jdk

variables:
  ADB_INSTALL_TIMEOUT: "5"
  ANDROID_COMPILE_SDK: "25"
  ANDROID_TEST_SDK: "22"
  ANDROID_ABI: "armeabi-v7a"
  ANDROID_BUILD_TOOLS: "25.0.2"
  ANDROID_SDK_TOOLS: "24.4.1"
  IS_CI_BUILD : "true"

before_script:
  - apt-get --quiet update --yes
  - apt-get --quiet install --yes wget tar unzip lib32stdc++6 lib32z1
  - wget --quiet --output-document=android-sdk.tgz https://dl.google.com/android/android-sdk_r$ANDROID_SDK_TOOLS-linux.tgz
  - tar --extract --gzip --file=android-sdk.tgz
  - echo y | android-sdk-linux/tools/android --silent update sdk --no-ui --all --filter android-$ANDROID_COMPILE_SDK
  - echo y | android-sdk-linux/tools/android --silent update sdk --no-ui --all --filter android-$ANDROID_TEST_SDK
  - echo y | android-sdk-linux/tools/android --silent update sdk --no-ui --all --filter platform-tools
  - echo y | android-sdk-linux/tools/android --silent update sdk --no-ui --all --filter build-tools-$ANDROID_BUILD_TOOLS
  - echo y | android-sdk-linux/tools/android --silent update sdk --no-ui --all --filter extra-android-m2repository
  - echo y | android-sdk-linux/tools/android --silent update sdk --no-ui --all --filter extra-google-google_play_services
  - echo y | android-sdk-linux/tools/android --silent update sdk --no-ui --all --filter extra-google-m2repository
  - export ANDROID_HOME=$PWD/android-sdk-linux
  - export PATH=$PATH:$PWD/android-sdk-linux/platform-tools/
  - chmod +x ./gradlew

stages:
  - build   #Generates the release and debug build
  - test    #Performs unit and insttrumentation tests.

debugBuild:   #Generate debug build for dev and master branch
  stage: build
  script:
    - ./gradlew assembleDebug
  only:
    - master
    - dev
  artifacts:
    paths:
    - app/build/outputs/

unitTests:  #Unit tests
  stage: test
  script:
    #Run the unit test
    - ./gradlew test

functionalTests:  #Instrumantation tests
  stage: test
  script:
     #Download the wait for emulator script
    - wget --quiet --output-document=android-wait-for-emulator https://raw.githubusercontent.com/travis-ci/travis-cookbooks/0f497eb71291b52a703143c5cd63a217c8766dc9/community-cookbooks/android-sdk/files/default/android-wait-for-emulator
    - chmod +x android-wait-for-emulator

    #Download emulator image for armeabi-v7a
    - echo y | android-sdk-linux/tools/android --silent update sdk --no-ui --all --filter sys-img-armeabi-v7a-google_apis-$ANDROID_TEST_SDK

    #Create AVD
    - echo no | android-sdk-linux/tools/android create avd --force -n test -t android-$ANDROID_TEST_SDK --abi google_apis/armeabi-v7a

    #Start the AVD and wait for the emulator to start
    - android-sdk-linux/tools/emulator64-arm -avd test -no-audio -no-window &
    - ./android-wait-for-emulator

    #Display list of devices
    - adb devices

    #Unloack device and run the instrumantation test
    - adb shell input keyevent 82 &
    - ./gradlew connectedAndroidTest

帮助我解决这个问题。我正在尝试运行它最后 4-5 天,但没有运气。

谢谢。

【问题讨论】:

【参考方案1】:

我也遇到过类似的问题,终于成功了这个配置

image: gengjiawen/android-ndk

stages:
  - build
  - test

build:
  stage: build
  script:
    - ./gradlew assembleDebug
  artifacts:
    paths:
    - app/build/outputs/

unitTests:
  stage: test
  script:
    - ./gradlew test

functionalTests:
  stage: test
  script:
    - sdkmanager "system-images;android-24;default;armeabi-v7a"
    - echo no | avdmanager create avd --force -n test -k "system-images;android-24;default;armeabi-v7a"
    - emulator -avd test -no-audio -no-window &
    - wget --quiet --output-document=android-wait-for-emulator https://raw.githubusercontent.com/travis-ci/travis-cookbooks/master/community-cookbooks/android-sdk/files/default/android-wait-for-emulator
    - chmod +x android-wait-for-emulator
    - ./android-wait-for-emulator
    - adb shell input keyevent 82
    - ./gradlew cAT

【讨论】:

以上是关于运行仪器测试离子Gitlab CI时出现不兼容的AVD错误的主要内容,如果未能解决你的问题,请参考以下文章

运行 Gitlab CI 作业以使用 webdriverio 执行自动化测试时出现“加载共享库时出错:libnss3.so”

训练模型时出现不兼容行维度的值错误

在 Windows 上安装 CUDA 时出现不兼容错误

在 Keras 中训练对象检测模型时出现不兼容张量形状的问题

从资源中读取文件在 gitlab CI 中不起作用

将 Capybara 升级到最新版本导致 Gitlab CI 失败