Travis-CI 运行 两个 android 模拟器

Travis-CI running two android emulators

我有一个用例,其中两个设备可以通过休息进行通信(点对点)。

我想在 Travis-CI 上测试这个用例。 Travis-CI android guide points to an example project:

language: android
jdk: oraclejdk7
env:
  matrix:
    - ANDROID_TARGET=android-19  ANDROID_ABI=armeabi-v7a

android:
  components:
    - build-tools-19.0.0

before_script:
  # Create and start emulator
  - echo no | android create avd --force -n test -t $ANDROID_TARGET --abi $ANDROID_ABI
  - emulator -avd test -no-skin -no-audio -no-window &
  - adb wait-for-device
  - adb shell input keyevent 82 &

script: ./gradlew connectedAndroidTest

从示例来看,我应该能够创建两个 AVD。

问题:Travis CI 环境是否支持创建和启动两个 AVD?

已更新

我发现以前的实验:

Build 599: Test wear experiment (6-7 minutes)

Build 600: Test two emulators simultaneously without boot-anim (6-7 minutes)

Build 601: Test two emulators simultaneously with boot-anim (10-15 minutes)

之前的回复:基于版本 605

我一年前试验过这种可能性(android + wear)但我不记得结果了。这取决于机器(使用 sudo: false 和容器基础设施,较新的机器)和您的脚本(避免 运行 同时执行繁重的任务,例如在创建其中一个模拟器时下载依赖项)。

我在 google 我的实验中搜索并找到了这个提交:

https://travis-ci.org/ardock/iosched/jobs/44038271 https://github.com/ardock/iosched/commit/88838ef1694b034f12b6ae4dc78615e8302689bd

Update compileSdkVersion and targetSdkVersion to 21.

Update wait_for_emulator.sh to support more than one emulator simultaneously. Add ANDROID_SERIAL env variable to support multiple emulators using adb/gradle. Create a second AVD with android-wear-20 as target by default. Start a second emulator for an android wear device. Add before_script logic to switch between emulators when using adb/gradle commands. Add optional ${WEAR_PKGS:-} variable to support specific android-wear-21 updates. Add new build matrix job allowing failures and using android-wear-21.

If ANDROID_SERIAL is defined, commands runs for a speficic device. The default behavior of running across all connected devices will occur if ANDROID_SERIAL is not defined or is empty. An exception will be thrown if the targeted DSN is not found. See https://android-review.googlesource.com/#/c/108985/

Currently we don't need a second emulator but can be useful in the future. Combining ANDROID_SERIAL and project names we can select a specific task for a specific project using Gradle.

我认为有限制是可能的。例如,您需要在等待模拟器脚本中删除 adb -e 标志,例如 here 并像这样使用 ANDROID_SERIAL 变量:

before_install:
  - export ANDROID_SERIAL='emulator-5554'
  - echo y | android update sdk -u -t platform-tool,tool,extra-android-m2repository,extra-google-m2repository
  - echo y | android update sdk -a -u -t ${BUILD_TOOLS},${MOBI_PKGS:-},${WEAR_PKGS:-}

install:
  - echo n | android create avd -f -n "${MOBI_NAME:-mobi}" -t "${MOBI_TARGET:-android-21}" -b
      "${MOBI_ABI:-armeabi-v7a}" -g "${MOBI_TAG:-default}"
  - echo n | android create avd -f -n "${WEAR_NAME:-wear}" -t "${WEAR_TARGET:-android-20}" -b
      "${WEAR_ABI:-armeabi-v7a}" -g "${WEAR_TAG:-android-wear}"
  - emulator -avd "${MOBI_NAME:-mobi}" -no-skin -no-audio -no-window &
  - emulator -avd "${WEAR_NAME:-wear}" -no-skin -no-audio -no-window &
  - adb wait-for-device get-serialno
  - ./gradlew --version
  - ./gradlew clean
  - ./gradlew compileDebugSources compileDebugTestSources compileReleaseSources

before_script:
  - ./scripts/wait_for_emulator.sh
  - adb shell input keyevent 82 &
  - adb logcat *:W | tee logcat.log>/dev/null 2>&1 &
  - ANDROID_SERIAL='emulator-5556'
  - adb wait-for-device get-serialno
  - ./scripts/wait_for_emulator.sh
  - adb shell input keyevent 82 &
  - ANDROID_SERIAL=''
  - adb devices -l

script:
  - ./gradlew build connectedCheck