Getting incompatible AVD error while running instrumentation test

I am getting below error whenever I am trying to run instrumentation test for my android project :

Skipping device 'test(AVD)' for 'app:': Unknown API Level

 > : No compatible devices connected.[TestRunner] FAILED 
Found 1 connected device(s), 0 of which were compatible.
:app:connectedDebugAndroidTest FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:connectedDebugAndroidTest'.
> There were failing tests. See the report at: file:///builds/antitheft/anti-theft-screen-lock/app/build/reports/androidTests/connected/index.html

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 2 mins 45.163 secs
ERROR: Job failed: exit code 1

I am using shared runner. My target API is 25 and I am trying to run the AVD on API 22.

Here is my gitlab-ci.yml file:

image: openjdk:8-jdk

variables:
  ADB_INSTALL_TIMEOUT: "5"
  ANDROID_COMPILE_SDK: "25"
  ANDROID_TEST_SDK: "22"
  ANDROID_ABI: "armeabi-v7a"
  ANDROID_BUILD_TOOLS: "25.0.2"
  ANDROID_SDK_TOOLS: "24.4.1"
  IS_CI_BUILD : "true"

before_script:
  - apt-get --quiet update --yes
  - apt-get --quiet install --yes wget tar unzip lib32stdc++6 lib32z1
  - wget --quiet --output-document=android-sdk.tgz https://dl.google.com/android/android-sdk_r${ANDROID_SDK_TOOLS}-linux.tgz
  - tar --extract --gzip --file=android-sdk.tgz
  - echo y | android-sdk-linux/tools/android --silent update sdk --no-ui --all --filter android-${ANDROID_COMPILE_SDK}
  - echo y | android-sdk-linux/tools/android --silent update sdk --no-ui --all --filter android-${ANDROID_TEST_SDK}
  - echo y | android-sdk-linux/tools/android --silent update sdk --no-ui --all --filter platform-tools
  - echo y | android-sdk-linux/tools/android --silent update sdk --no-ui --all --filter build-tools-${ANDROID_BUILD_TOOLS}
  - echo y | android-sdk-linux/tools/android --silent update sdk --no-ui --all --filter extra-android-m2repository
  - echo y | android-sdk-linux/tools/android --silent update sdk --no-ui --all --filter extra-google-google_play_services
  - echo y | android-sdk-linux/tools/android --silent update sdk --no-ui --all --filter extra-google-m2repository
  - export ANDROID_HOME=$PWD/android-sdk-linux
  - export PATH=$PATH:$PWD/android-sdk-linux/platform-tools/
  - chmod +x ./gradlew

stages:
  - build   #Generates the release and debug build
  - test    #Performs unit and insttrumentation tests.

debugBuild:   #Generate debug build for dev and master branch
  stage: build
  script:
    - ./gradlew assembleDebug
  only:
    - master
    - dev
  artifacts:
    paths:
    - app/build/outputs/

unitTests:  #Unit tests
  stage: test
  script:
    #Run the unit test
    - ./gradlew test

functionalTests:  #Instrumantation tests
  stage: test
  script:
     #Download the wait for emulator script
    - 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

    #Download emulator image for armeabi-v7a
    - echo y | android-sdk-linux/tools/android --silent update sdk --no-ui --all --filter sys-img-armeabi-v7a-google_apis-${ANDROID_TEST_SDK}

    #Create AVD
    - echo no | android-sdk-linux/tools/android create avd --force -n test -t android-${ANDROID_TEST_SDK} --abi google_apis/armeabi-v7a

    #Start the AVD and wait for the emulator to start
    - android-sdk-linux/tools/emulator64-arm -avd test -no-audio -no-window &
    - ./android-wait-for-emulator

    #Display list of devices
    - adb devices

    #Unloack device and run the instrumantation test
    - adb shell input keyevent 82 &
    - ./gradlew connectedAndroidTest

Help me with resolving this issue. I am trying to run it for last 4-5 days with no luck.

Thank you.

I am facing the same issue with a similar configuration. @kevalpatel2106 Did you manage to find a solution?

Even though this topic is already open for a long time, I ran into the same problem and want to share my solution.

First of all, in the current android sdk, the android executable is deprecated. Try using android-sdk-linux/tools/bin/sdkmanager (see this post for more in-depth explanations).

Even though I don’t know the exact reason, the ARM architecture is not compatible with GitLab Runners. I assume they run on an emulated Intel core or sth. (only speculation and no real background knowledge on my side).

Another problem is, that the x86 images require KVM hardware acceleration. Currently, that is not supported from every shared runner. The runners with the do-tag do support KVM though. The following code worked for me (no extra kvm installations or configurations needed):

    - ../linux-sdk-tools/tools/bin/sdkmanager "system-images;android-${ANDROID_COMPILE_SDK};google_apis;x86"
    - echo no | ../linux-sdk-tools/tools/bin/avdmanager create avd -n testAVD -k "system-images;android-${ANDROID_COMPILE_SDK};google_apis;x86"
    - ../linux-sdk-tools/tools/emulator -avd testAVD -no-audio -no-window &
    - ./android-wait-for-emulator

Hope that helps everyone stumbling about this.

do tag is not available and now listed in shared-runners list. May be this can be a solution https://gitlab.com/gitlab-org/gitlab-runner/issues/2242#note_121185541