Q:

Travis CI android emulator can't be created with avdmanager

I want to build and test an Android app using an emulator in Travis CI.
On my local machine I can create emulator with both android and avdmanager tools, examples:
echo no | android create avd --force --name test01 --package 'system-images;android-27;google_apis_playstore;x86'

echo no | avdmanager create avd --force --name test02 --package 'system-images;android-27;google_apis_playstore;x86' 

But on Travis there's no avdmanager in $ANDROID_HOME/tools/bin

When I tried to create emulator with android tool (which isn't desired because it's deprecated) it turned out that it's different from version installed on my mac and requires different parameters

My .travis.yml file (vars and build steps removed for clarity):
sudo: true
os: linux
dist: trusty
language: android

android:
  components:
  - build-tools-26.0.2
  - android-26

before_script:
- echo no | android create avd --force --name test --package 'system-images;android-27;google_apis_playstore;x86'
#- echo no | avdmanager create avd --force --name test --package 'system-images;android-27;google_apis_playstore;x86'

script:
- echo "DEBUG searching for avdmanager" && ls -lAp $ANDROID_HOME/tools/bin

So could you please advice how should I create Android emulator in Travis CI?  

A:

After playing around the official ways, the simplest way I found to launch one emulator on travis has at least this in travis.xml
before_install:
  # Install SDK license so Android Gradle plugin can install deps.
  - mkdir "$ANDROID_HOME/licenses" || true
  - echo "d56f5187479451eabf01fb78af6dfcb131a6481e" >> "$ANDROID_HOME/licenses/android-sdk-license"
  # Install the rest of tools (e.g. avdmanager)
  - sdkmanager tools
  # Install the system image.
  - sdkmanager "system-images;android-24;default;armeabi-v7a"
  # Create and start emulator for the script. Meant to race the install task.
  - echo no | avdmanager create avd --force -n emulatorApi24 -k "system-images;android-24;default;armeabi-v7a"
  - $ANDROID_HOME/emulator/emulator -avd emulatorApi24 -no-audio -no-window &

before_script:
  - android-wait-for-emulator
  # Disable animations
  - adb shell settings put global window_animation_scale 0 &
  - adb shell settings put global transition_animation_scale 0 &
  - adb shell settings put global animator_duration_scale 0 &
  - adb shell input keyevent 82 &

script: ./gradlew connectedAndroidTest # Run emulator tests

Now my travis build takes 20 minutes :D
As a reference, a good place to check a working example is the U+2020 project.

