Last active
December 2, 2024 08:47
-
-
Save illuzor/988385c493d3f7ed7193a6e3ce001a68 to your computer and use it in GitHub Desktop.
Config for gitlab ci android with unit tests and instrumented tests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
image: ubuntu:22.04 | |
variables: | |
ANDROID_COMPILE_SDK: "33" | |
ANDROID_BUILD_TOOLS: "33.0.2" | |
EMULATOR_IMAGE: "24" | |
SDK_TOOLS: "9477386" # from https://developer.android.com/studio/#command-tools | |
before_script: | |
# install required packages | |
- apt-get update --yes | |
- apt-get install wget gnupg gnupg2 unzip --yes | |
# install liberica jdk 11 https://bell-sw.com/libericajdk/ | |
- wget -q -O - https://download.bell-sw.com/pki/GPG-KEY-bellsoft | apt-key add - | |
- echo "deb [arch=amd64] https://apt.bell-sw.com/ stable main" | tee /etc/apt/sources.list.d/bellsoft.list | |
- apt-get --quiet update --yes | |
- apt-get install bellsoft-java11-lite --yes | |
- java -version | |
# download and unzip android sdk | |
- wget --quiet --output-document=android-sdk.zip https://dl.google.com/android/repository/commandlinetools-linux-${SDK_TOOLS}_latest.zip | |
- echo A | unzip -q android-sdk.zip -d android-sdk-linux | |
- rm android-sdk.zip | |
# export gradle home path | |
- export GRADLE_USER_HOME=$PWD/.gradle | |
# export android sdk path | |
- export ANDROID_SDK_ROOT=$PWD/android-sdk-linux | |
# export android sdk executables paths | |
- export PATH=$PATH:$ANDROID_SDK_ROOT/cmdline-tools/latest/bin/ | |
- export PATH=$PATH:$ANDROID_SDK_ROOT/platform-tools/ | |
- export PATH=$PATH:$ANDROID_SDK_ROOT/emulator/ | |
# hack with moving cmdline-tools to cmdline-tools/latest, no idea how to install directly | |
- mkdir $ANDROID_SDK_ROOT/cmdline-tools/latest | |
- mv $ANDROID_SDK_ROOT/cmdline-tools/{lib,bin,source.properties,NOTICE.txt} $ANDROID_SDK_ROOT/cmdline-tools/latest | |
# update and install common android sdk components | |
- sdkmanager --sdk_root=${ANDROID_SDK_ROOT} --update | |
- echo y | sdkmanager --sdk_root=${ANDROID_SDK_ROOT} "platforms;android-${ANDROID_COMPILE_SDK}" "build-tools;${ANDROID_BUILD_TOOLS}" | |
- chmod +x ./gradlew | |
stages: | |
- test | |
unit tests: | |
stage: test | |
script: | |
- ./gradlew testDebugUnitTest | |
artifacts: | |
when: always | |
reports: | |
junit: [ | |
./**/build/test-results/testDebugUnitTest/TEST-*.xml, | |
] | |
instrumented tests: | |
stage: test | |
script: | |
# install packages needed by emulator | |
- apt-get install libx11-dev libpulse0 libgl1 libnss3 libxcomposite-dev libxcursor1 libasound2 --yes | |
# install android sdk components and emulator | |
- sdkmanager --sdk_root=${ANDROID_SDK_ROOT} "platform-tools" "emulator" "system-images;android-${EMULATOR_IMAGE};default;armeabi-v7a" | |
# download script for emulator waiting | |
- wget --quiet --output-document=android-wait-for-emulator https://raw.githubusercontent.com/travis-ci/travis-cookbooks/0f497eb71291b52a703143c5cd63a217c8766dc9/community-cookbooks/android-sdk/files/default/android-wait-for-emulator | |
- chmod +x android-wait-for-emulator | |
# create virtual device named "test" | |
- echo no | avdmanager -v create avd -n test -k "system-images;android-${EMULATOR_IMAGE};default;armeabi-v7a" | |
# start adb server | |
- adb start-server | |
# run emulator and tests | |
- emulator -avd test -no-boot-anim -no-window -no-audio -no-snapshot & | |
- ./android-wait-for-emulator | |
- adb shell input keyevent 82 | |
- ./gradlew connectedDebugAndroidTest | |
artifacts: | |
when: always | |
reports: | |
junit: [ | |
./**/build/outputs/androidTest-results/connected/TEST-*.xml, | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The last armeabi-v7a was for system image 25, after that only viable option was arm64-v8a . Anyone tried system image 26 and up?