Jing Li Jing Li - 2 years ago 112
Android Question

How to run Android UI tests properly on CircleCI 2.0?

Trying to upgrade my Android project to CircleCI 2.0. Everything is fine, but having trouble of running Android UI tests with emulator.


  • Log says
    com.android.builder.testing.api.DeviceException: No connected devices!

  • I've actually downloaded an emulator image and set it up (coz CircleCI's default Android Docker image doesn't come with emulator):
    sdkmanager "system-images;android-22;default;armeabi-v7a" && echo "no" | avdmanager create avd -n test -k "system-images;android-22;default;armeabi-v7a" && (emulator64-arm -avd test -noaudio -no-boot-anim -no-window -accel on) &

  • adb devices
    returns no device :(


Answer Source

Example circle.yml:

version: 2
jobs:
  build:
    docker:
      - image: circleci/android:api-26-alpha
    steps:
      - run:
          name: Setup emulator
          command: sdkmanager "system-images;android-22;default;armeabi-v7a" && echo "no" | avdmanager create avd -n test -k "system-images;android-22;default;armeabi-v7a"
      - run:
          name: Launch emulator
          command: export LD_LIBRARY_PATH=${ANDROID_HOME}/emulator/lib64:${ANDROID_HOME}/emulator/lib64/qt/lib && emulator64-arm -avd test -noaudio -no-boot-anim -no-window -accel on
          background: true
      - run:
          name: Run Tests
          command: ./gradlew :demo:connectedAndroidTest

Note:

  • Some certain architecture image is not provided by Google, e.g. API level 26 doesn't have ARM EABI v7a System Image, that's why I choose system-images;android-22;default;armeabi-v7a above. To see which images are available, run command sdkmanager --list --verbose | grep system-images.

  • You need to set an environment variable LD_LIBRARY_PATH with lib64 and qt path, otherwise you'll probably encounter ERROR: Could not load OpenGLES emulation library [lib64OpenglRender] or error while loading shared libraries: libQt5Widgets.so.5: cannot open shared object file: No such file or directory Exited with code 127. This is due to a bug from Android SDK.

  • To run a command in the background on CircleCI, it's not like the usual way just append & to the end of command, that will be killed by the hangup (HUP) signal eventually. The correct way is to say background: true.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download