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:
before_install:
- 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
android:
components:
- 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
licenses:
- 'android-sdk-preview-license-.+'
- 'android-sdk-license-.+'
- 'google-gdk-license-.+'
before_install:
# - chmod +x gradlew
- yes | sdkmanager "platforms;android-30"
before_script:
- 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 &
before_cache:
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
- rm -fr $HOME/.gradle/caches/*/plugin-resolution/
cache:
directories:
- $HOME/.gradle/caches/
- $HOME/.gradle/wrapper/
- $HOME/.android/build-cache
script:
- 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
env:
- CODECOV_TOKEN=a-code-is-here
after_success:
- bash <(curl -s https://codecov.io/bash)
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!
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:
https://travis-ci.community/t/add-kvm-support/1406
Which seems to have solutions to this problem, I believe i’ve used the following two links as templates:
https://github.com/ankidroid/Anki-Android/pull/5594/files
https://github.com/hannesa2/DbPreferences/pull/5/files
sudo: true
language: generic
dist: bionic
addons:
apt:
packages:
- bridge-utils
- libpulse0
- libvirt-bin
- qemu-kvm
- virtinst
- ubuntu-vm-builder
env:
global:
- CODECOV_TOKEN=eae3e3fd-ce8e-47e2-a3c0-928c84551a60
- ABI=x86_64
- ADB_INSTALL_TIMEOUT=8
- ANDROID_HOME=${HOME}/android-sdk
- ANDROID_TOOLS_URL="https://dl.google.com/android/repository/sdk-tools-linux-4333796.zip"
- EMU_FLAVOR=default # use google_apis flavor if no default flavor emulator
- GRAVIS="https://raw.githubusercontent.com/DanySK/Gravis-CI/master/"
- 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}
matrix:
#- 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
before_install:
# - chmod +x gradlew
# Set up KVM
- sudo adduser $USER libvirt
- sudo adduser $USER kvm
# Set up JDK 8 for Android SDK
- curl "${GRAVIS}.install-jdk-travis.sh" --output ~/.install-jdk-travis.sh
- export TARGET_JDK="${JDK}"
- JDK="1.8"
- source ~/.install-jdk-travis.sh
# Set up Android SDK
- wget -q "${ANDROID_TOOLS_URL}" -O android-sdk-tools.zip
- unzip -q android-sdk-tools.zip -d ${ANDROID_HOME}
- rm android-sdk-tools.zip
# Avoid harmless sdkmanager warning
#- mkdir ~/.android
- echo 'count=0' > ~/.android/repositories.cfg
# Accept all Android license agreements
- yes | sdkmanager --licenses
install:
# 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 gradle.properties
- 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"
EMU_COMMAND="emulator"
#if [[ $ABI =~ "x86" ]]; then
# EMU_COMMAND="emulator-headless"
#fi
# 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/android-wait-for-emulator.sh
- adb shell input keyevent 82 &
# Switch back to our target JDK version to build and run tests
- JDK="${TARGET_JDK}"
- source ~/.install-jdk-travis.sh
before_cache:
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
- rm -fr $HOME/.gradle/caches/*/plugin-resolution/
- curl "${GRAVIS}.clean_gradle_cache.sh" --output ~/.clean_gradle_cache.sh
- bash ~/.clean_gradle_cache.sh
cache:
directories:
- $HOME/.gradle/caches/
- $HOME/.gradle/wrapper/
- $HOME/.android/build-cache
script:
- 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
after_success:
- bash <(curl -s https://codecov.io/bash)
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!