Android 24 Google APIs emulator does not boot

android

#1

We have recently found that the latest revision of the Android 24 Google APIs ABI results in an emulator that cannot boot on CircleCI. This is due to a bug in the Android kernel: the latest revision of the emulator cannot create a frame buffer on systems that don’t have a hardware GPU. We have filed a bug in the Android bug tracker.

In the meanwhile, you can work around this in the following two ways.

Using the default Android ABI instead of the Google APIs one

If your application does not require a Google APIs ABI, you might want to use a default ABI in your build. This one relies on an older Android kernel version and therefore boots successfully on CircleCI. You can use the default ABI in your build like this:

test:
  override:
    # launch the default Android 24 emulator
    - emulator -avd circleci-android24 -no-window -gpu off:
        background: true
        parallel: true
    - circle-android wait-for-boot
    # run tests against the emulator
    - ./gradlew connectedAndroidTest:
        timeout: 720

Downgrading Google APIs ABI to the previous version

If your application relies on the Google APIs being available in the emulator, using the default Android emulator will not work for you. As the current version of Google APIs ABI does not boot on CircleCI, you can add the following to your circle.yml to run an emulator using the previous version of Google APIs system image:

dependencies:
  pre:
   - echo y | android update sdk --no-ui --all --filter "android-24"
    # Android SDK Platform 25 Build Tools
    - echo y | android update sdk --no-ui --all --filter "tools"
    # Android SDK Platform Tools 24.0.2
    - echo y | android update sdk --no-ui --all --filter "platform-tools"
    # Android SDK Build-tools, revision 24.0.2
    - echo y | android update sdk --no-ui --all --filter "build-tools-24.0.1"
    # Android Support Repository, revision 35 / Local Maven repository for Support Libraries
    - echo y | android update sdk --no-ui --all --filter "extra-android-m2repository"
    # Android 24 ARM Google APIs system Image
    - echo y | android update sdk --no-ui --all --filter "sys-img-armeabi-v7a-google_apis-24"
    # Create the android 24 AVD
    - echo no | android create avd -n circleci-android24-googleapis -t 'android-24' --abi google_apis/armeabi-v7a
    - |
      # software rendering is broken in revision 10, we'll use revision 08
      wget "https://dl-ssl.google.com/android/repository/sys-img/google_apis/armeabi-v7a-24_r08.zip"
      unzip armeabi-v7a-24_r08.zip
      # overwrite some of the new files with older files
      mv armeabi-v7a/* /usr/local/android-sdk-linux/system-images/android-24/google_apis/armeabi-v7a
      rm armeabi-v7a-24_r08.zip

test:
  override:  
    - emulator -avd circleci-android24-googleapis -no-window -gpu off:
        background: true
        parallel: true
    - circle-android wait-for-boot
    # run tests  against the emulator
    - ./gradlew connectedAndroidTest:
        timeout: 720

Please reply to this post if you have any questions about this.


Android Emulator Timeout Error
Android 24 with Google APIs
#2

Has this solution worked for anyone? I had to add dashes before the last four uncommented lines of dependencies/pre, but now I’m getting
Error: Android Virtual Device 'circleci-android24-googleapis' already exists.
for the line: echo no | android create avd -n circleci-android24-googleapis -t 'android-24' --abi google_apis/armeabi-v7a returned exit code 1. Should that line be removed? Or changed in some way? Thanks.


#3

You can try

echo no | android create avd -n circleci-android24-googleapis -t || echo "The emulator is already there."


#4

@roberrera You will still need to create the virtual device, so that line should be there.

Please let us know if @danielgomezrico’s suggestion works for you.


#5

Thanks for your replies. I was in touch with a CircleCI customer support representative and I got the config below working.

My problem is I was caching the ~/.android directory, which is where the emulator is created, so the solution was to remove that directory from my caching commands and select rebuild without cache.

dependencies:
    pre:
      - echo y | android update sdk --no-ui --all --filter "android-24"
      # Android SDK Platform 25 Build Tools
      - echo y | android update sdk --no-ui --all --filter "tools"
      # Android SDK Platform Tools 25.0.3
      - echo y | android update sdk --no-ui --all --filter "platform-tools"
      # Android SDK Build-tools, revision 25.0.2
      - echo y | android update sdk --no-ui --all --filter "build-tools-25.0.2"
      # Android Support Repository, revision 35 / Local Maven repository for Support Libraries
      - echo y | android update sdk --no-ui --all --filter "extra-android-m2repository"
      # Android 24 ARM Google APIs system Image
      - echo y | android update sdk --no-ui --all --filter "sys-img-armeabi-v7a-google_apis-24"
      # Create the android 24 AVD
      - echo no | android create avd -n circleci-android24-googleapis -t 'android-24' --abi google_apis/armeabi-v7a
      # software rendering is broken in revision 10, we'll use revision 08
      - wget "https://dl-ssl.google.com/android/repository/sys-img/google_apis/armeabi-v7a-24_r08.zip"
      - unzip armeabi-v7a-24_r08.zip
      # overwrite some of the new files with older files
      - mv armeabi-v7a/* /usr/local/android-sdk-linux/system-images/android-24/google_apis/armeabi-v7a
      - rm armeabi-v7a-24_r08.zip

    override:
      - ANDROID_HOME=/usr/local/android-sdk-linux ./gradlew dependencies

    cache_directories:
      - ~/.gradle
      - /usr/local/android-sdk-linux/tools
      - /usr/local/android-sdk-linux/platforms/android-24
      - /usr/local/android-sdk-linux/build-tools/25.0.2
      - /usr/local/android-sdk-linux/extras/android/m2repository

test:
    override:
    # set up emulator
      - emulator -avd circleci-android24-googleapis -no-window -gpu off:
          background: true
          parallel: true
    # wait for emulator to boot
      - circle-android wait-for-boot
    # unlock the emulator
      - sleep 30
      - adb shell input keyevent 82
    # run tests against the emulator and generate report and limit gradle's memory usage
      - ./gradlew clean jacocoTestReport
    # copy the build outputs to artifacts
      - cp -r app/build/outputs $CIRCLE_ARTIFACTS
    # copy the test results to the test results directory
      - cp -r app/build/reports/jacoco/* $CIRCLE_TEST_REPORTS

#6

@roberrera Glad that it worked itself out!

Please don’t hesitate if you have any questions or concerns.


#8

I’ve tried using this:

test:
pre:
- emulator -avd circleci-android24 -no-audio -no-window -gpu off:
background: true
parallel: true
- circle-android wait-for-boot

But the emulator never boots, and just eats up valuable build minutes. I don’t need the Google APIs, but the suggested solution in that scenario doesn’t seem to work.

More generally CircleCI is fantastic, although with the caveat that getting Android builds working on it has been pretty painful. It’s taken me around 20hrs to get builds working with JVM unit tests, instrumented tests and test coverage reports for both, but only with API 22, and without much optimisation so each build takes around 19mins which seems excessive. Hopefully in time the ability to cache dependencies, better support the Android emulator (or Genymotion?) and better docs will help. It would be great to see a much more comprehensive example circle.yml that support running JVM and instrumented tests, test coverage reports for both, lint reports, and the ability to fail builds for failing to meet quality targets.


#9

Hi @alexey,

I tried what are you suggestion but it’s still not working. The error I’m facing is:

Building 42% > :chat:connectedDebugAndroidTest:chat:connectedDebugAndroidTest

: No compatible devices connected.[TestRunner] FAILED
Building 42% > :chat:connectedDebugAndroidTestFound 1 connected device(s), 0 of which were compatible.
Building 42% > :chat:connectedDebugAndroidTest:chat:connectedDebugAndroidTest FAILED

Can you help me?


#10

Any solution for your issue? Can you please share us your circle.yml?


#11

I’ve had good luck using the swiftshader GPU - take a look at this project:

https://github.com/marcomorain/android-24-demo , specifically the yml: https://github.com/marcomorain/android-24-demo/blob/master/circle.yml


#12