简体   繁体   English

运行两个Android模拟器的Travis-CI

[英]Travis-CI running two android emulators

I have a use case where two devices can communicate (peer-2-peer) over rest. 我有一个用例,其中两个设备可以在休息状态下进行通信(对等2对等)。

I'd like to test this use case on Travis-CI. 我想在Travis-CI上测试此用例。 The Travis-CI android guide points to an example project : Travis-CI android指南指向一个示例项目

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

It appears from the example that I should be able to create two AVD's. 从该示例看来,我应该能够创建两个AVD。

Question: will the Travis CI environment support creating and starting two AVD's? 问题: Travis CI环境是否支持创建和启动两个AVD?

Updated 更新

I found previous experiments: 我找到了以前的实验:

Build 599: Test wear experiment (6-7 minutes) 组建599:测试磨损实验(6-7分钟)

Build 600: Test two emulators simultaneously without boot-anim (6-7 minutes) Build 600:在没有启动动画的情况下同时测试两个仿真器(6-7分钟)

Build 601: Test two emulators simultaneously with boot-anim (10-15 minutes) 版本601:使用启动动画同时测试两个仿真器(10-15分钟)

Previous response: based on build 605 先前的响应:基于版本605

I experimented this possibility a year ago (android + wear) but I don't remember the results. 我在一年前尝试过这种可能性(Android + Wear),但我不记得结果了。 This depends on the machines (use sudo: false and the container infrastructure, newer machines) and your script (avoid to run simultaneously heavy tasks like downloading dependencies while one of the emulators is being created). 这取决于机器(使用sudo: false和容器基础结构,较新的机器)和您的脚本(避免在创建其中一个仿真器时同时运行繁重的任务,例如下载依赖项)。

I searched in google my experiments and found this commit: 我在Google的实验中进行了搜索,发现该提交:

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

Update compileSdkVersion and targetSdkVersion to 21. 将compileSdkVersion和targetSdkVersion更新为21。

Update wait_for_emulator.sh to support more than one emulator simultaneously. 更新wait_for_emulator.sh以同时支持多个模拟器。 Add ANDROID_SERIAL env variable to support multiple emulators using adb/gradle. 添加ANDROID_SERIAL env变量以使用adb / gradle支持多个仿真器。 Create a second AVD with android-wear-20 as target by default. 默认情况下,使用android-wear-20创建第二个AVD。 Start a second emulator for an android wear device. 为Android Wear设备启动第二个模拟器。 Add before_script logic to switch between emulators when using adb/gradle commands. 使用adb / gradle命令时,添加before_script逻辑可在仿真器之间切换。 Add optional ${WEAR_PKGS:-} variable to support specific android-wear-21 updates. 添加可选的$ {WEAR_PKGS:-}变量以支持特定的android-wear-21更新。 Add new build matrix job allowing failures and using android-wear-21. 添加允许失败的新构建矩阵作业,并使用android-wear-21。

If ANDROID_SERIAL is defined, commands runs for a speficic device. 如果定义了ANDROID_SERIAL,则为特定设备运行命令。 The default behavior of running across all connected devices will occur if ANDROID_SERIAL is not defined or is empty. 如果未定义ANDROID_SERIAL或为空,则将在所有连接的设备上运行默认行为。 An exception will be thrown if the targeted DSN is not found. 如果找不到目标DSN,则将引发异常。 See https://android-review.googlesource.com/#/c/108985/ 参见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. 结合ANDROID_SERIAL和项目名称,我们可以使用Gradle为特定项目选择特定任务。

I think that it's possible with restrictions. 我认为可能有限制。 For example you'll need to delete the adb -e flag in the wait for emulator script like here and play with the ANDROID_SERIAL variable like this: 例如,您将需要在等待模拟器脚本中删除adb -e标志,如下所示并使用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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM