android-emulator-runner: Emulator failed to boot

When running the emulator on GitHub Actions (macos-latest), we occasionally get an error of Timeout waiting for emulator to boot. This is probably around 25-30% of test runs that we get this. I did a dive into the differences between a successful build and this error in terms of logs, but couldn’t spot anything obvious.

The build logs are as follows:

2023-02-16T21:02:48.9274480Z ##[group]Launch Emulator
2023-02-16T21:02:48.9355520Z Creating AVD.
2023-02-16T21:02:48.9371150Z [command]/bin/sh -c \echo no | avdmanager create avd --force -n test --abi 'default/x86' --package 'system-images;android-24;default;x86'
2023-02-16T21:02:51.4707730Z Loading local repository...                                                     
2023-02-16T21:02:51.4746140Z [=========                              ] 25% Loading local repository...       
2023-02-16T21:02:51.4747010Z [=========                              ] 25% Fetch remote repository...        
2023-02-16T21:02:51.4747400Z [=======================================] 100% Fetch remote repository...       
2023-02-16T21:02:52.3224520Z Do you wish to create a custom hardware profile? [no] [command]/bin/sh -c \printf 'hw.cpu.ncore=2
2023-02-16T21:02:52.3225790Z ' >> /Users/runner/.android/avd/test.avd/config.ini
2023-02-16T21:02:52.3298780Z Starting emulator.
2023-02-16T21:02:52.3328190Z [command]/bin/sh -c \/Users/runner/Library/Android/sdk/emulator/emulator -avd test -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim &
2023-02-16T21:02:53.0896040Z INFO    | Android emulator version 32.1.11.0 (build_id 9536276) (CL:N/A)
2023-02-16T21:02:53.1265250Z INFO    | Found systemPath /Users/runner/Library/Android/sdk/system-images/android-24/default/x86/
2023-02-16T21:02:53.1366860Z INFO    | Found systemPath /Users/runner/Library/Android/sdk/system-images/android-24/default/x86/
2023-02-16T21:02:56.3485370Z WARNING | encryption is off
2023-02-16T21:02:56.3600450Z WARNING | Running on a system with less than 6 logical cores. Setting number of virtual cores to 1
2023-02-16T21:02:57.1046830Z ERROR   | Unable to connect to adb daemon on port: 5037
2023-02-16T21:02:58.0422260Z WARNING | cannot add library /Users/runner/Library/Android/sdk/emulator/qemu/darwin-x86_64/lib64/vulkan/libvulkan.dylib: failed
2023-02-16T21:02:58.0520210Z INFO    | Crashreporting disabled, not reporting crashes.
2023-02-16T21:02:58.0622110Z INFO    | Duplicate loglines will be removed, if you wish to see each indiviudal line launch with the -log-nofilter flag.
2023-02-16T21:02:58.1968680Z WARNING | /etc/localtime does not point to zoneinfo-compatible timezone name
2023-02-16T21:02:58.2072600Z WARNING | *** No gRPC protection active, consider launching with the -grpc-use-jwt flag.***
2023-02-16T21:02:58.2421060Z [command]/Users/runner/Library/Android/sdk/platform-tools/adb shell getprop sys.boot_completed
2023-02-16T21:02:58.2641090Z * daemon not running; starting now at tcp:5037
2023-02-16T21:02:58.7321700Z * daemon started successfully
2023-02-16T21:02:58.7334000Z adb: no devices/emulators found
2023-02-16T21:02:58.7349340Z The process '/Users/runner/Library/Android/sdk/platform-tools/adb' failed with exit code 1
2023-02-16T21:03:00.7425490Z [command]/Users/runner/Library/Android/sdk/platform-tools/adb shell getprop sys.boot_completed
2023-02-16T21:03:00.7634680Z adb: no devices/emulators found
2023-02-16T21:03:00.7650360Z The process '/Users/runner/Library/Android/sdk/platform-tools/adb' failed with exit code 1
2023-02-16T21:03:02.7681960Z [command]/Users/runner/Library/Android/sdk/platform-tools/adb shell getprop sys.boot_completed
2023-02-16T21:03:02.7908520Z adb: no devices/emulators found

---- Repeat many times ----

/Users/runner/Library/Android/sdk/platform-tools/adb -s emulator-5554 emu kill
error: could not connect to TCP port 5554: Connection refused
The process '/Users/runner/Library/Android/sdk/platform-tools/adb' failed with exit code 1

Our workflow file can be found at: https://github.com/ably/ably-asset-tracking-android/blob/main/.github/workflows/emulate.yml

Thanks! 😃

About this issue

  • Original URL
  • State: open
  • Created a year ago
  • Reactions: 19
  • Comments: 23

Commits related to this issue

Most upvoted comments

Same story, timeout in most cases:

776 /usr/local/lib/android/sdk/platform-tools/adb shell getprop sys.boot_completed
777 /usr/local/lib/android/sdk/platform-tools/adb shell getprop sys.boot_completed
Terminate Emulator
778 /usr/local/lib/android/sdk/platform-tools/adb -s emulator-5554 emu kill
779 INFO    | Wait for emulator (pid 2385) 20 seconds to shutdown gracefully before kill;you can set environment variable ANDROID_EMULATOR_WAIT_TIME_BEFORE_KILL(in seconds) to change the default value (20 seconds)
780 OK: killing emulator, bye bye
781 OK
782 Error: Timeout waiting for emulator to boot.

I am seeing a similar issue on API 29 and 33 (haven’t tried any other), but in my case adb seems to get online after a while. For some reason adb shell getprop sys.boot_completed doesn’t seem to return whatever the action is expecting (testing locally, my emulator returns 1) and it loops seemingly forever.

  /usr/local/lib/android/sdk/platform-tools/adb shell getprop sys.boot_completed
  adb: device offline
  The process '/usr/local/lib/android/sdk/platform-tools/adb' failed with exit code 1
  /usr/local/lib/android/sdk/platform-tools/adb shell getprop sys.boot_completed
  adb: device offline
  The process '/usr/local/lib/android/sdk/platform-tools/adb' failed with exit code 1
  /usr/local/lib/android/sdk/platform-tools/adb shell getprop sys.boot_completed
  adb: device offline
  The process '/usr/local/lib/android/sdk/platform-tools/adb' failed with exit code 1
  /usr/local/lib/android/sdk/platform-tools/adb shell getprop sys.boot_completed
  /usr/local/lib/android/sdk/platform-tools/adb shell getprop sys.boot_completed
  /usr/local/lib/android/sdk/platform-tools/adb shell getprop sys.boot_completed
  /usr/local/lib/android/sdk/platform-tools/adb shell getprop sys.boot_completed
  /usr/local/lib/android/sdk/platform-tools/adb shell getprop sys.boot_completed

After adding the free-disk-space step

  • we also had to switch from the mac image (faster) to ubuntu-latest as free-disk-space action does not support the mac image: sudo: swapoff: command not found [...] free: command not found

  • After switching to ubuntu-latest, the emulator still does not start: Error: Timeout waiting for emulator to boot.

  • So we also added the KVM step from nowinandroid which also didn’t fix it.

  • We finally also borrowed the other configurations from notinandroid which finally fixed the emulator startup!

Having the same issue here

+1 Also experiencing this for past 3 days. Seems to fail 70-80% of the time

I noticed that in the Android official example project, someone merged in this change with a git commit mentioning “to fix CI”

Another PR was linked in the above PR’s description where this relevant conversation was held.

After seeing this, I decided to implement the free-disk-space action within my workflow and it seems it may have resolved the emulator failing to boot. This is a recent change for my workflow so hopefully I’ll know after enough runs if it’s truly fixed or not.

Same issue:

WARNING | Failed to process .ini file /home/runner/.android/emu-update-last-check.ini for reading.
  /usr/local/lib/android/sdk/platform-tools/adb shell getprop sys.boot_completed
  * daemon not running; starting now at tcp:5037
  * daemon started successfully
  adb: device offline
  The process '/usr/local/lib/android/sdk/platform-tools/adb' failed with exit code 1
  /usr/local/lib/android/sdk/platform-tools/adb shell getprop sys.boot_completed
  1
  Emulator booted.
  /usr/local/lib/android/sdk/platform-tools/adb shell input keyevent 82
  Disabling animations.
  /usr/local/lib/android/sdk/platform-tools/adb shell settings put global window_animation_scale 0.0
  /usr/local/lib/android/sdk/platform-tools/adb shell settings put global transition_animation_scale 0.0
  /usr/local/lib/android/sdk/platform-tools/adb shell settings put global animator_duration_scale 0.0
/usr/bin/sh -c echo "Generated AVD snapshot for caching."

My YML:

name: Run test
on: push
jobs:
  build:
    name: Run integration test
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4.1.1
      - name: Java setup
        uses: actions/setup-java@v4.0.0
        with:
          java-version: '17'
          distribution: 'zulu'
      - name: Flutter setup
        uses: subosito/flutter-action@v2.12.0
        with:
          channel: 'stable'
      - name: Enable KVM group perms
        run: |
          echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
          sudo udevadm control --reload-rules
          sudo udevadm trigger --name-match=kvm
      - name: Run Android emulator
        uses: reactivecircus/android-emulator-runner@v2
        with:
          api-level: 29
          script: echo "Generated AVD snapshot for caching."
      - run: flutter doctor -v
      - run: flutter pub get
      - run: flutter pub run build_runner build --delete-conflicting-outputs
      - run: flutter test integration_test
      - run: flutter test

Just noting here that we were seeing the same error when using a self-hosted ARM64 runner (always fails with adb: no devices/emulators found). After some digging, the root cause seemed to be the same as #239 . We started defining an avd-name, and now the emulator consistently boots and runs the tests.

Our current working action is:

- name: Run UI Tests
  uses: reactivecircus/android-emulator-runner@v2
  with:
    api-level: 31
    profile: Nexus 6
    arch: arm64-v8a
    force-avd-creation: false
    avd-name: macOS-avd-arm64-v8a-31
    emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
    disable-animations: true
    script: ./gradlew connectedCheck

I ended up firing up a Firebase Test Lab test from my Github Action. It’s not as elegant as having everything running neatly in my own runner, but it’ll do for now.

It looks like the main workflow of this repo is also failing with the same problem we are all having 😕 Is there any more information on what the problem is and when it will probably be fixed? Thank you in advance 😃

Same here. Running on 4-core latest ubuntu and it maybe starts 15% of time.

Hey friends we are hitting this as well with Store

Also running into the same since last 3 days.