I want to run a pipeline that includes android app instrumented tests, which require an android emulator.
I am using the image
: nvcr.io/nvidia/cuda:12.1.1-base-ubuntu22.04
(from GPU-enabled hosted runners | GitLab)
I want an image that will allow me to run android emulator which requires hardward acceleration.
Although I have installed KVM, when I run
kvm-ok
I am getting the error:
INFO: Your CPU does not support KVM extensions
KVM acceleration can NOT be used
What do I need to do to fix this?
This is my .gitlab-ci.yml
file:
image: eclipse-temurin:17-jdk-jammy
variables:
# ANDROID_COMPILE_SDK is the version of Android you're compiling with.
# It should match compileSdkVersion.
ANDROID_COMPILE_SDK: "34"
# It's what version of the command line tools we're going to download from the official site.
# Official Site-> https://developer.android.com/studio/index.html
# There, look down below at the cli tools only, sdk tools package is of format:
# commandlinetools-os_type-ANDROID_SDK_TOOLS_latest.zip
# when the script was last modified for latest compileSdkVersion, it was which is written down below
ANDROID_SDK_TOOLS: "11076708"
GRADLE_OPTS: "-Dorg.gradle.daemon=false"
EMULATOR_IMAGE: "android-34;default;x86_64"
# Packages installation before running script
before_script:
- apt-get --quiet update --yes
- apt-get --quiet install --yes wget unzip
# install JAVA
- apt install --yes openjdk-17-jdk
- echo "export JAVA_HOME=$(dirname $(dirname $(readlink -f $(which java))))" >> ~/.bashrc
- source ~/.bashrc
# Setup path as android_home for moving/exporting the downloaded sdk into it
- export ANDROID_HOME="${PWD}/android-sdk-root"
# Create a new directory at specified location
- install -d $ANDROID_HOME
# Here we are installing androidSDK tools from official source,
# (the key thing here is the url from where you are downloading these sdk tool for command line, so please do note this url pattern there and here as well)
# after that unzipping those tools and
# then running a series of SDK manager commands to install necessary android SDK packages that'll allow the app to build
- wget --no-verbose --output-document=$ANDROID_HOME/cmdline-tools.zip https://dl.google.com/android/repository/commandlinetools-linux-${ANDROID_SDK_TOOLS}_latest.zip
- unzip -q -d "$ANDROID_HOME/cmdline-tools" "$ANDROID_HOME/cmdline-tools.zip"
- mv -T "$ANDROID_HOME/cmdline-tools/cmdline-tools" "$ANDROID_HOME/cmdline-tools/tools"
- export PATH=$PATH:$ANDROID_HOME/cmdline-tools/latest/bin:$ANDROID_HOME/cmdline-tools/tools/bin:$ANDROID_HOME/platform-tools:$ANDROID_HOME/emulator
# Nothing fancy here, just checking sdkManager version
- sdkmanager --version
# use yes to accept all licenses
- yes | sdkmanager --licenses > /dev/null || true
- sdkmanager --update
- sdkmanager "platforms;android-${ANDROID_COMPILE_SDK}"
- sdkmanager "platform-tools"
- sdkmanager "build-tools;${ANDROID_COMPILE_SDK}.0.0"
# Not necessary, but just for surity
- chmod +x ./gradlew
stages:
- test
# Run all tests, if any fails, interrupt the pipeline(fail it)
# Currently commented out, because I can't make the emulator run
#
# I am facing the same problem that it is described here:
# https://forum.gitlab.com/t/error-while-performing-test-on-gitlab-ci-for-android/7203?u=panos9
#
androidTests:
interruptible: true
stage: test
tags:
- saas-linux-medium-amd64-gpu-standard
image: mixlrdev/nvcr-io-nvidia-cuda-12-1-1-base-ubuntu22-04-kvm:latest
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 "emulator" "system-images;${EMULATOR_IMAGE}"
# 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;${EMULATOR_IMAGE}"
# start adb server
- adb start-server
- echo "KVM support?"
- kvm-ok
# run emulator and tests
- emulator -avd test -no-boot-anim -no-window -no-audio -no-snapshot -gpu auto &
- ./android-wait-for-emulator
- ./gradlew -Pci --console=plain connectedAndroidTest
artifacts:
when: always
paths:
- 'app/build/reports/'
tests:
interruptible: true
stage: test
script:
- ./gradlew -Pci --console=plain test
artifacts:
when: always
paths:
- '**/build/reports/'
The mixlrdev/nvcr-io-nvidia-cuda-12-1-1-base-ubuntu22-04-kvm:latest
is built with the following Dockerfile
:
FROM nvcr.io/nvidia/cuda:12.1.1-base-ubuntu22.04
# Install necessary packages
RUN apt-get update && \
apt-get install -y qemu-kvm libvirt-daemon-system libvirt-clients bridge-utils kmod virt-manager && \
groupadd kvm && \
# Ensure libvirtd is started
RUN systemctl enable libvirtd
# Expose necessary ports
EXPOSE 5900 16509
# Start libvirtd
CMD ["/sbin/init"]