SHC SHC - 1 year ago 148
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
- ANDROID_TARGET=android-19 ANDROID_ABI=armeabi-v7a

- build-tools-19.0.0

# 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 Source


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:

Update compileSdkVersion and targetSdkVersion to 21.

Update 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

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:

  - 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:-}

  - 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

  - ./scripts/
  - 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/
  - adb shell input keyevent 82 &
  - adb devices -l

  - ./gradlew build connectedCheck
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download