5

I have python wrapper-library for adb where I have unit-test which depend on emulator or real device (since they execute adb commands).

I want also to use Travis CI as build environment along with executing those unit tests for each build.

Is there a way to have android emulator available somewhow in Travis CI, so that unit tests can execute adb commands?

Thanks in advance!

Viktor Malyi
  • 2,298
  • 2
  • 23
  • 40

2 Answers2

7

According to the Travis CI documentation, you can start an emulator with the following script in your .travis.yml:

# Emulator Management: Create, Start and Wait
before_script:
  - echo no | android create avd --force -n test -t android-19 --abi armeabi-v7a
  - emulator -avd test -no-skin -no-audio -no-window &
  - android-wait-for-emulator
  - adb shell input keyevent 82 &

Just specify the system image you need in components.

Bruno Parmentier
  • 1,219
  • 2
  • 14
  • 34
5

Bruno Parmentier's answer includes what Travis-CI is currently recommending, but I had issues with the VM running out of memory. So instead of running the emulator while the build is running, I changed my config to run the build, then start the emulator, then run the tests.

sudo: false

language: android

env:
  global:
    # switch glibc to a memory conserving mode
    - MALLOC_ARENA_MAX=2
    # wait up to 10 minutes for adb to connect to emulator
    - ADB_INSTALL_TIMEOUT=10

android:
  components:
    - platform-tools
    - extra-android-m2repository
    - build-tools-22.0.1
    - android-22
    - sys-img-armeabi-v7a-android-22

script:
  - ./gradlew assemble lint

after_script:
  # Emulator Management: Create, Start and Wait
  - echo no | android create avd --force -n test -t android-22 --abi armeabi-v7a
  - emulator -avd test -no-skin -no-audio -no-window &
  - android-wait-for-emulator
  - adb shell input keyevent 82 &
  # now run the tests
  - ./gradlew connectedCheck
  • Thanks for your answer, but the question was about having emulator started and not about how to manage memory consumption issues – Viktor Malyi Sep 25 '15 at 13:40
  • 2
    I've had a lot of problems actually getting the emulator to start and run reliably on travis-ci. This is what I had to do in order to actually run the emulator in a useful way. If the basic version works for your job, lucky you :) – Hans-Christoph Steiner Nov 06 '15 at 15:22
  • Sir, I just want to thank you. You saved my day, three days trying to figure out how to execute Espresso tests and when I was just giving up, your after_script suggestion worked like a charm. – Thomaz Freitas Barbosa Aug 03 '17 at 18:57