runner-images icon indicating copy to clipboard operation
runner-images copied to clipboard

Android Emulator on API 31 fails to launch on macos-12

Open ssrinivasKG opened this issue 1 year ago • 8 comments

Description

Android emulator for API 31 configured in the yml file shown below fails to launch. Logs show the following error repeatedly qemu-system-x86_64[4472:17343] [CAMetalLayer nextDrawable] returning nil because device is nil.

As can be seen in the below yml file, installing intel haxm has no effect on whether the emulator launches without any errors

Test yml file:

# This is a basic workflow to help you get started with Actions

name: EMU_test_MacOS12

# Controls when the workflow will run
on:
  # Triggers the workflow on push or pull request events but only for the "main" branch
  
  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

jobs:
  run-emulator:
    runs-on: macos-12
  
    steps: 
    
    - name: set up JDK 17
      uses: actions/setup-java@v3
      with:
        java-version: '17'
        distribution: 'temurin'
    
    - name: Setup Android SDK
      uses: android-actions/setup-android@v2
      
    - name: Setup gradle
      uses: gradle/gradle-build-action@v2    
        
    - name: Create Android emulator
      run: |
        # install the hardware acceleration
        echo " Installing Hardware Acceleration Manager..."
        sudo $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --install "extras;intel;Hardware_Accelerated_Execution_Manager"
        # brew install intel-haxm
        sysctl kern.hv_support
        sdkmanager --install "system-images;android-31;google_apis;x86_64"
        echo "no" | avdmanager --verbose create avd --force --name TestAvd123 --abi google_apis/x86_64 --package 'system-images;android-31;google_apis;x86_64'
        echo "AVD created:"
        "$ANDROID_HOME/emulator/emulator" -list-avds
          
        echo "Starting the Android emulator..."
        export ANDROID_EMULATOR_DEBUG=1
        nohup "$ANDROID_HOME/emulator/emulator" -avd TestAvd123 -accel on -gpu swiftshader_indirect -no-snapshot-load 2>&1 &
        $ANDROID_HOME/platform-tools/adb wait-for-device
        echo "Emulator has finished booting"
        $ANDROID_HOME/platform-tools/adb devices
        sleep 45
        screencapture screenshot.jpg
        $ANDROID_HOME/platform-tools/adb exec-out screencap -p > emulator.png
          
    - name: install recorder and record session
      run: |
          brew install ffmpeg
          $ANDROID_HOME/tools/emulator -port 18725 -verbose -accel on -no-audio -gpu swiftshader_indirect @TestAvd123 &
          ffmpeg -f avfoundation -i 0 -t 45 out.mov
          # node -e "const exec = require('child_process'); exec.exec('ffmpeg -f avfoundation -i 0 -t 120 out.mov'); exec.exec('$ANDROID_HOME/tools/emulator -port 18725 -verbose -no-window -no-audio -gpu swiftshader_indirect @Pixel_5_API_31 &');"
      env:
           HOMEBREW_NO_INSTALL_CLEANUP: 1
          
    - name: upload video
      uses: actions/upload-artifact@master
      with:
            name: out
            path: out.mov
             
    - uses: actions/upload-artifact@v3
      with:
           name: screenshot.jpg
           path: screenshot.jpg
             
    - uses: actions/upload-artifact@v3
      with:
           name: emulator.png
           path: emulator.png

Platforms affected

  • [ ] Azure DevOps
  • [X] GitHub Actions - Standard Runners
  • [ ] GitHub Actions - Larger Runners

Runner images affected

  • [ ] Ubuntu 18.04
  • [ ] Ubuntu 20.04
  • [ ] Ubuntu 22.04
  • [ ] macOS 10.15
  • [X] macOS 11
  • [X] macOS 12
  • [ ] Windows Server 2019
  • [ ] Windows Server 2022

Image version and build link

2.297.0

Is it regression?

N/A

Expected behavior

Android emulator starts and runs successfully without errors

Actual behavior

Android emulator fails to launch with a grey screen and errors thrown on console.

screenshot 5

https://user-images.githubusercontent.com/73707428/194652728-62e40f62-f79a-4230-a297-dd3617d54d3f.mov

Repro steps

Run the yml file below

# This is a basic workflow to help you get started with Actions

name: EMU_test_MacOS12

# Controls when the workflow will run
on:
  # Triggers the workflow on push or pull request events but only for the "main" branch
  
  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

jobs:
  run-emulator:
    runs-on: macos-12
  
    steps: 
    
    - name: set up JDK 17
      uses: actions/setup-java@v3
      with:
        java-version: '17'
        distribution: 'temurin'
    
    - name: Setup Android SDK
      uses: android-actions/setup-android@v2
      
    - name: Setup gradle
      uses: gradle/gradle-build-action@v2    
        
    - name: Create Android emulator
      run: |
        # install the hardware acceleration
        echo " Installing Hardware Acceleration Manager..."
        sudo $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --install "extras;intel;Hardware_Accelerated_Execution_Manager"
        # brew install intel-haxm
        sysctl kern.hv_support
        sdkmanager --install "system-images;android-31;google_apis;x86_64"
        echo "no" | avdmanager --verbose create avd --force --name TestAvd123 --abi google_apis/x86_64 --package 'system-images;android-31;google_apis;x86_64'
        echo "AVD created:"
        "$ANDROID_HOME/emulator/emulator" -list-avds
          
        echo "Starting the Android emulator..."
        export ANDROID_EMULATOR_DEBUG=1
        nohup "$ANDROID_HOME/emulator/emulator" -avd TestAvd123 -accel on -gpu swiftshader_indirect -no-snapshot-load 2>&1 &
        $ANDROID_HOME/platform-tools/adb wait-for-device
        echo "Emulator has finished booting"
        $ANDROID_HOME/platform-tools/adb devices
        sleep 45
        screencapture screenshot.jpg
        $ANDROID_HOME/platform-tools/adb exec-out screencap -p > emulator.png
          
    - name: install recorder and record session
      run: |
          brew install ffmpeg
          $ANDROID_HOME/tools/emulator -port 18725 -verbose -accel on -no-audio -gpu swiftshader_indirect @TestAvd123 &
          ffmpeg -f avfoundation -i 0 -t 45 out.mov
          # node -e "const exec = require('child_process'); exec.exec('ffmpeg -f avfoundation -i 0 -t 120 out.mov'); exec.exec('$ANDROID_HOME/tools/emulator -port 18725 -verbose -no-window -no-audio -gpu swiftshader_indirect @Pixel_5_API_31 &');"
      env:
           HOMEBREW_NO_INSTALL_CLEANUP: 1
          
    - name: upload video
      uses: actions/upload-artifact@master
      with:
            name: out
            path: out.mov
             
    - uses: actions/upload-artifact@v3
      with:
           name: screenshot.jpg
           path: screenshot.jpg
             
    - uses: actions/upload-artifact@v3
      with:
           name: emulator.png
           path: emulator.png

ssrinivasKG avatar Oct 07 '22 21:10 ssrinivasKG

Hi @ssrinivasKG, thank you for report, we will take a look.

igorboskovic3 avatar Oct 10 '22 07:10 igorboskovic3

Hi @ssrinivasKG did you check this thread.

You can use this snippet and it should work

steps: 
   - name: Create Android emulator
     run: |
      brew install intel-haxm
      # Install AVD files
      echo "y" | $ANDROID_HOME/tools/bin/sdkmanager --install 'system-images;android-27;default;x86_64'
      echo "y" | $ANDROID_HOME/tools/bin/sdkmanager --licenses
      
      # Create emulator
      $ANDROID_HOME/tools/bin/avdmanager create avd -n Pixel_API_29_AOSP -d pixel --package 'system-images;android-27;default;x86_64'
      $ANDROID_HOME/emulator/emulator -list-avds
      if false; then
      emulator_config=~/.android/avd/Pixel_API_29_AOSP.avd/config.ini
      # The following madness is to support empty OR populated config.ini files,
      # the state of which is dependant on the version of the emulator used (which we don't control),
      # so let's be defensive to be safe.
      # Replace existing config (NOTE we're on MacOS so sed works differently!)
      sed -i .bak 's/hw.lcd.density=.*/hw.lcd.density=420/' "$emulator_config"
      sed -i .bak 's/hw.lcd.height=.*/hw.lcd.height=1920/' "$emulator_config"
      sed -i .bak 's/hw.lcd.width=.*/hw.lcd.width=1080/' "$emulator_config"
      # Or, add new config
      if ! grep -q "hw.lcd.density" "$emulator_config"; then
        echo "hw.lcd.density=420" >> "$emulator_config"
      fi
      if ! grep -q "hw.lcd.height" "$emulator_config"; then
        echo "hw.lcd.height=1920" >> "$emulator_config"
      fi
      if ! grep -q "hw.lcd.width" "$emulator_config"; then
        echo "hw.lcd.width=1080" >> "$emulator_config"
      fi
      echo "Emulator settings ($emulator_config)"
      cat "$emulator_config"
      fi
      
   - name: Start Android emulator
     run: |
      echo "Starting emulator and waiting for boot to complete...."
      ls -la $ANDROID_HOME/emulator
      nohup $ANDROID_HOME/tools/emulator -avd Pixel_API_29_AOSP -gpu host -no-audio -no-boot-anim -camera-back none -camera-front none -qemu -m 2048 2>&1 &
      $ANDROID_HOME/platform-tools/adb wait-for-device shell 'while [[ -z $(getprop sys.boot_completed | tr -d '\r') ]]; do echo "wait..."; sleep 1; done; input keyevent 82'
      echo "Emulator has finished booting"
      $ANDROID_HOME/platform-tools/adb devices
      sleep 30
      screencapture screenshot.jpg
      $ANDROID_HOME/platform-tools/adb exec-out screencap -p > emulator.png
   - name: install recorder and record session
     run: |
      brew install ffmpeg
      $ANDROID_HOME/tools/emulator -port 18725 -verbose -no-window -no-audio -gpu swiftshader_indirect @Pixel_API_29_AOSP &
      ffmpeg -f avfoundation -i 0 -t 120 out.mov
  # node -e "const exec = require('child_process'); exec.exec('ffmpeg -f avfoundation -i 0 -t 120 out.mov'); exec.exec('$ANDROID_HOME/tools/emulator -port 18725 -verbose -no-window -no-audio -gpu swiftshader_indirect @Pixel_5_API_31 &');"
     env:
      HOMEBREW_NO_INSTALL_CLEANUP: 1
   - name: upload video
     uses: actions/upload-artifact@master
     with:
      name: out
      path: out.mov
      
   - uses: actions/upload-artifact@v3
     with:
      name: screenshot.jpg
      path: screenshot.jpg
      
   - uses: actions/upload-artifact@v3
     with:
      name: emulator.png
      path: emulator.png`

igorboskovic3 avatar Oct 12 '22 09:10 igorboskovic3

@igorboskovic3 Yes i did try that. For API's greater than 27 the emulator fails to start. It is stuck in the while loop for over 15 minutes. My guess is that is because of the display not launching.

ssrinivasKG avatar Oct 12 '22 17:10 ssrinivasKG

@ssrinivasKG yes, you are right, we cannot use API`s greater then 27, can you try to use 27?

igorboskovic3 avatar Oct 13 '22 10:10 igorboskovic3

@ssrinivasKG My conclusion is that is performance issue and we cannot do much regarding that

igorboskovic3 avatar Oct 13 '22 10:10 igorboskovic3

@igorboskovic3 would that be the same even if it was for github enterprise? Is there a different dedicated support portal for that?

ssrinivasKG avatar Oct 13 '22 12:10 ssrinivasKG

@ssrinivasKG Yes it is a same , because there is no difference between agents.

igorboskovic3 avatar Oct 13 '22 12:10 igorboskovic3

I saw the same problem randomly on local 8Gb mac pro during the high load and suggests the problem is with the low performance of VMs used to execute the pipelines.

dsame avatar Nov 28 '22 08:11 dsame

@ssrinivasKG @igorboskovic3 i believe the issue can be closed as we have nothing to do with the pure performance of the mac os build machines.

dsame avatar Dec 20 '22 09:12 dsame