Trying to get Android build with SDK bigger than 22

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)
1 Like