How to run Android UI tests properly on CircleCI 2.0?

Viewed 3801

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 :(
2 Answers

Following is an example config.yml with which i managed to get my Android espresso tests working some time back using circle ci. May be useful for someone.

Location of the config.yml: create .circleci directory at root of the project and keep config.yml inside that.

version: 2
jobs:
  build:
    working_directory: ~/code
    docker:
      - image: circleci/android:api-28-alpha
    environment:
      JVM_OPTS: -Xmx3200m
    steps:
      - checkout
      - restore_cache:
          key: jars-{{ checksum "build.gradle" }}-{{ checksum  "app/build.gradle" }}
      - run:
         name: Chmod permissions
         command: sudo chmod +x ./gradlew
      - run:
          name: Download Dependencies
          command: ./gradlew androidDependencies
      - save_cache:
          paths:
            - ~/.gradle
          key: jars-{{ checksum "build.gradle" }}-{{ checksum  "app/build.gradle" }}
      - run:
          name: Lists installed targets
          command: android list target
          environment:
          TERM: dumb
      - run:
          name: Show list of system-images
          command: sdkmanager --list --verbose | grep system-images
      - run:
          name: Setup Emulator
          command: sdkmanager "system-images;android-21;default;armeabi-v7a" && echo "no" | avdmanager create avd -n test -k "system-images;android-21;default;armeabi-v7a"
      - run:
          name: Launch Emulator
          command: |
                  cd ${ANDROID_HOME}/emulator;ls
                  export LD_LIBRARY_PATH=${ANDROID_HOME}/emulator/lib64:${ANDROID_HOME}/emulator/lib64/qt/lib
                  emulator -avd test -no-window -noaudio -no-boot-anim -no-window -accel on
          background: true
      - run:
          name: Wait emulator
          command: |
              circle-android wait-for-boot
              adb shell input keyevent 82
      - run:
          name: Run Espresso UI Tests
          command: ./gradlew :app:connectedDebugAndroidTest
      - store_artifacts:
          path: app/build/reports
          destination: reports
      - store_test_results:
          path: app/build/test-results
Related