SHC SHC - 3 months ago 57
Android Question

Travis-CI running two android emulators

I have a use case where two devices can communicate (peer-2-peer) over rest.

I'd like to test this use case on Travis-CI. The 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


It appears from the example that I should be able to create two AVD's.

Question: will the Travis CI environment support creating and starting two AVD's?

Answer

Updated

I found previous experiments:

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)

Previous response: based on build 605

I experimented this possibility a year ago (android + wear) but I don't remember the results. 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).

I searched in google my experiments and found this commit:

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.

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:

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