ReactiveCircus / android-emulator-runner

A GitHub Action for installing, configuring and running hardware-accelerated Android Emulators on macOS virtual machines.
Apache License 2.0
946 stars 186 forks source link

Running emulator with cache on multiple jobs causes the jobs to hang. #362

Open syedahmedjamil opened 8 months ago

syedahmedjamil commented 8 months ago

I want to run the emulator with cache on two jobs in parallel but the jobs seems to just hang at the end when its time to terminate the emulator. Instead the step keeps running and workflow doesn't ends.

Note: If I remove the step "AVD cache" and "create AVD and generate snapshot for caching" from both jobs then it works fine.

Why does it hang with cache ?

my-workflow.yml file

name: My Workflow

on:
  pull_request:
    branches: [ "dev" ]

jobs:
  job1:
    runs-on: macos-latest
    strategy:
      matrix:
        api-level: [29]
    steps:
      - name: checkout
        uses: actions/checkout@v3

      - name: Gradle cache
        uses: gradle/gradle-build-action@v2

      - name: AVD cache
        uses: actions/cache@v3
        id: avd-cache
        with:
          path: |
            ~/.android/avd/*
            ~/.android/adb*
          key: avd-${{ matrix.api-level }}

      - name: create AVD and generate snapshot for caching
        if: steps.avd-cache.outputs.cache-hit != 'true'
        uses: reactivecircus/android-emulator-runner@v2
        with:
          api-level: ${{ matrix.api-level }}
          force-avd-creation: false
          emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
          disable-animations: false
          script: echo "Generated AVD snapshot for caching."

      - name: run tests
        uses: reactivecircus/android-emulator-runner@v2
        with:
          api-level: ${{ matrix.api-level }}
          force-avd-creation: false
          emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
          disable-animations: true
          script: echo "Done"

  job2:
    runs-on: macos-latest
    strategy:
      matrix:
        api-level: [29]
    steps:
      - name: checkout
        uses: actions/checkout@v3

      - name: Gradle cache
        uses: gradle/gradle-build-action@v2

      - name: AVD cache
        uses: actions/cache@v3
        id: avd-cache
        with:
          path: |
            ~/.android/avd/*
            ~/.android/adb*
          key: avd-${{ matrix.api-level }}

      - name: create AVD and generate snapshot for caching
        if: steps.avd-cache.outputs.cache-hit != 'true'
        uses: reactivecircus/android-emulator-runner@v2
        with:
          api-level: ${{ matrix.api-level }}
          force-avd-creation: false
          emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
          disable-animations: false
          script: echo "Generated AVD snapshot for caching."

      - name: run tests
        uses: reactivecircus/android-emulator-runner@v2
        with:
          api-level: ${{ matrix.api-level }}
          force-avd-creation: false
          emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
          disable-animations: true
          script: echo "Done"

job1 state image

job2 state image

fillobotto commented 8 months ago

I'm experiencing the same problem

ericswpark commented 6 months ago

Same issue here. CI gets stuck if AVD is cached: https://github.com/Purdue-CS307-tsundoku/tsundoku/actions/runs/8320789292/job/22766040436 I had to manually cancel the workflow run.

MohitMaliFtechiz commented 4 months ago

I am facing this error too in https://github.com/kiwix/kiwix-android/pull/3806 when the job the completed then it stuck on terminating the emulator.

  1. https://github.com/kiwix/kiwix-android/actions/runs/8844204274/job/24286763179?pr=3806
  2. https://github.com/kiwix/kiwix-android/actions/runs/8844204274/job/24285666360?pr=3806