Error while performing test on GitLab CI for android

I am getting below warning when I am performing functional UI tests on gitlab ci for my android project.

emulator: ERROR: x86 emulation currently requires hardware acceleration!
Please ensure KVM is properly installed and usable.
CPU acceleration status: KVM is not installed on this machine (/dev/kvm is missing).

Because of above error emulator doesn’t start and a timeout error occurs.

Help me with resolving this issue.

1 Like

Please provide more info;

  • what kind of runner
  • runner host info
  • your gitlab ci.yml

any update on this bro , am facing the same error, suggest me any solution am using self hosted gitlab runner in linux. @stefanvangastel @kevalpatel2106

I am facing the same problem today.

I am using the eclipse-temurin:17-jdk-jammy image.

Here is the .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

  # 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)
androidTests:
  interruptible: true
  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 "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

    # run emulator and tests
    - emulator -avd test -no-boot-anim -no-window -no-audio -no-snapshot &
    - ./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 androidTests fail with error:

ERROR   | x86_64 emulation currently requires hardware acceleration!

I have tried using arm64 image but it was not compatible with the QEMU emulator.

So, I am stuck.

Any suggestions?