Trying to get Android build with SDK bigger than 22

I’m struggling to get try and get Travis to build an android project with an emulator that is a higher SDK level than 22?

You need to add the following line to your .travis.yml configuration file:

- yes | sdkmanager "platforms;android-30"

It would also be helpful in the future to see your .travis.yml. If there’s sensitive information in it, just supply the areas that are giving you concern.

Thanks for getting back to me @Montana

Here is my current .travis.yml

sudo: required

language: android
dist: trusty
    - tools
    - build-tools-30.0.2
    - android-30
    - android-22
    - extra-google-google_play_services
    - extra-google-m2repository
    - extra-android-m2repository
    - sys-img-armeabi-v7a-android-22
  - 'android-sdk-preview-license-.+'
  - 'android-sdk-license-.+'
  - 'google-gdk-license-.+'
#  - chmod +x gradlew
  - yes | sdkmanager "platforms;android-30"
  - echo no | android create avd --force -n test -t android-22 --abi armeabi-v7a
  - emulator -avd test -no-audio -no-window &
  #- 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 &
  - android-wait-for-emulator
  - adb shell input keyevent 82 &
  - rm -f  $HOME/.gradle/caches/modules-2/modules-2.lock
  - rm -fr $HOME/.gradle/caches/*/plugin-resolution/

  - $HOME/.gradle/caches/
  - $HOME/.gradle/wrapper/
  - $HOME/.android/build-cache
  - cd WifiMapper
  - adb shell appops set com.riba2reality.exeterlocate 58 allow
  - ./gradlew clean test build
# - ./gradlew jacocoTestReport
# - ./gradlew createDebugCoverageReport
# - ./gradlew connectedCheck #instrucment tests
  - ./gradlew jacocoTestReport

  - CODECOV_TOKEN=a-code-is-here

  - bash <(curl -s

This project is now Open-Source, so feel free to take a look GitHub - MJGibson/Exeter_Locate: Exeter locate application and associated server setup

I’ve recently been adding a few tests. At this time of posting, i was trying to set up mock locations in the android emulator, but that is only available from SDK 25+
As you can see I am using the Android-30 platform as you and other guides advise, but using the suggested travis setup for the emulator appears to be using android-22.

Furthermore, as I’ve been adding some other test recently my builds appear to either have become intermittent in their successes (on the same builds, sometimes working, sometimes not), to the point where I can’t seem to get them to work. Mainly seems to be stemming from the use of the old emulator… I think.
maybe there is some time out I’ve missed?

Hello Dr. Gibson,

Let me take a look at this for you and see if I can’t get a working build for you by tweaking some of the specs in the travis.yml file!

1 Like

Hi @Montana,

I’ve been debugging some builds, and it appears the problem is one of virtualisation for the Android emulator, which limits us to only using an image with armeabi-v7a architecture. Which really limits the highest Android SDK you can build for as Google stopped supporting this architecture some time ago.

I can’t remember where I got the inspiration but searched for KVM and Travis and stumbled across:
Which seems to have solutions to this problem, I believe i’ve used the following two links as templates:

sudo: true
language: generic
dist: bionic

      - bridge-utils
      - libpulse0
      - libvirt-bin
      - qemu-kvm
      - virtinst
      - ubuntu-vm-builder
    - CODECOV_TOKEN=eae3e3fd-ce8e-47e2-a3c0-928c84551a60
    - ABI=x86_64
    - ANDROID_HOME=${HOME}/android-sdk
    - EMU_FLAVOR=default # use google_apis flavor if no default flavor emulator
    - GRAVIS=""
    - JDK="1.8"
    - TOOLS=${ANDROID_HOME}/tools
    # PATH order is incredibly important. e.g. the 'emulator' script exists in more than one place!
    - PATH=${ANDROID_HOME}:${ANDROID_HOME}/emulator:${TOOLS}:${TOOLS}/bin:${ANDROID_HOME}/platform-tools:${PATH}
   #- API=15 # only runs locally. Create+Start once from AndroidStudio to init sdcard. Then only from command-line w/-engine classic
   - API=16 ABI=x86 AUDIO=-no-audio
   - API=17 ABI=x86
   - API=18 ABI=x86 # API18 has started being flaky
   #- API=19 ABI=armeabi-v7a # Fails: kernel/emulator mismatch, and emulator-29+ doesn't support "-engine classic" to fix
   # API 20 was Android Wear only
   - API=21
   - API=22
   - API=23
   - API=24
   - API=25
   #- API=26 # Fails with unrecognized tests? orchestrator change or something?
   - API=27
   - API=28
   - API=29
   - API=30

#  - chmod +x gradlew
  # Set up KVM
  - sudo adduser $USER libvirt
  - sudo adduser $USER kvm

  # Set up JDK 8 for Android SDK
  - curl "${GRAVIS}" --output ~/
  - export TARGET_JDK="${JDK}"
  - JDK="1.8"
  - source ~/

  # Set up Android SDK
  - wget -q "${ANDROID_TOOLS_URL}" -O
  - unzip -q -d ${ANDROID_HOME}
  - rm

  # Avoid harmless sdkmanager warning  
  #- mkdir ~/.android
  - echo 'count=0' > ~/.android/repositories.cfg

  # Accept all Android license agreements
  - yes | sdkmanager --licenses

  # Download SDK tools
  - echo y | sdkmanager "platform-tools" >/dev/null
  - echo y | sdkmanager "tools" >/dev/null # A second time per Travis docs, gets latest versions
  - echo y | sdkmanager "build-tools;28.0.3" >/dev/null # Implicit gradle dependency - gradle drives changes
  - echo y | sdkmanager "platforms;android-$API" >/dev/null # We need the API of the emulator we will run
  - echo y | sdkmanager "platforms;android-28" >/dev/null # We need the API of the current compileSdkVersion from
  - echo y | sdkmanager "emulator" >/dev/null
  - echo y | sdkmanager "extras;android;m2repository" >/dev/null
  - echo y | sdkmanager "system-images;android-$API;$EMU_FLAVOR;$ABI" >/dev/null # install our emulator

  # Create an Android emulator
  - echo no | avdmanager create avd --force -n test -k "system-images;android-$API;$EMU_FLAVOR;$ABI" -c 10M
  - |
    EMU_PARAMS="-verbose -no-snapshot -no-window -camera-back none -camera-front none -selinux permissive -qemu -m 2048"
    #if [[ $ABI =~ "x86" ]]; then
    #  EMU_COMMAND="emulator-headless"
    # This double "sudo" monstrosity is used to have Travis execute the
    # emulator with its new group permissions and help preserve the rule
    # of least privilege.
    sudo -E sudo -u $USER -E bash -c "${ANDROID_HOME}/emulator/${EMU_COMMAND} -avd test ${AUDIO} ${EMU_PARAMS} &"
  # Wait for emulator to be ready
  - ./tools/
  - adb shell input keyevent 82 &

  # Switch back to our target JDK version to build and run tests
  - source ~/


  - rm -f  $HOME/.gradle/caches/modules-2/modules-2.lock
  - rm -fr $HOME/.gradle/caches/*/plugin-resolution/
  - curl "${GRAVIS}" --output ~/
  - bash ~/

  - $HOME/.gradle/caches/
  - $HOME/.gradle/wrapper/
  - $HOME/.android/build-cache
  - cd WifiMapper
  #- adb shell appops set com.riba2reality.exeterlocate 58 allow
  - ./gradlew clean test build
# - ./gradlew jacocoTestReport
# - ./gradlew createDebugCoverageReport
# - ./gradlew connectedCheck #instrucment tests
  - ./gradlew jacocoTestReport

  - bash <(curl -s
1 Like

Very interesting,

I was just looking back into this, I appreciate you linking these PR’s, this is maybe something we could add in our documentation.

Thanks @MJGibson!