'Azure DevOps: Android emulator script timeout

Experiencing continuous timeout errors when using the official bash command for downloading and starting the Android emulator on an Azure DevOps hosted agent using vmImage: macos-latest. According to the documentation it should boot an emulator and then continue with the emulator running in background.

This is my definition in our .yml file.

pool:
  vmImage: 'macos-latest'

[...]

- script: |
    echo "y" | $ANDROID_HOME/tools/bin/sdkmanager --install "system-images;android-29;google_apis;x86"
    echo "no" | $ANDROID_HOME/tools/bin/avdmanager create avd --force --name emu --device "Pixel_API_29_AOSP" -k 'system-images;android-29;google_apis;x86'
    $ANDROID_HOME/emulator/emulator -list-avds
  condition: ne(variables.AVD_IMAGES_RESTORED, 'true')
  displayName: 'Download Android Emulator Image'
  env:
    JAVA_HOME: $(JAVA_HOME_8_X64)
    PATH: $(JAVA_HOME_8_X64)/bin:$(PATH)


- script: |
    echo "Starting emulator"
    nohup $ANDROID_HOME/emulator/emulator -avd emu -no-snapshot -no-audio -no-boot-anim -accel auto -gpu auto -qemu -lcd-density 420 > /dev/null 2>&1 &
    $ANDROID_HOME/platform-tools/adb wait-for-device shell 'while [[ -z $(getprop sys.boot_completed | tr -d '\r') ]]; do sleep 1; done; input keyevent 82'
    $ANDROID_HOME/platform-tools/adb devices
    echo "Emulator started"
  displayName: 'Android Emulator'

And these are the logs that are output until the job gets cancelled due to timeout (60 minutes):

Starting: Android Emulator
==============================================================================
Task         : Bash
Description  : Run a Bash script on macOS, Linux, or Windows
Version      : 3.198.0
Author       : Microsoft Corporation
Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/bash
==============================================================================
Generating script.
========================== Starting Command Output ===========================
/bin/bash /Users/runner/work/_temp/3b8f2c22-dd8f-40ad-9cf0-972eca407beb.sh
Starting emulator
* daemon not running; starting now at tcp:5037
* daemon started successfully

Do anyone have any experience with getting the Android emulator script to work on macos-latest? Is there anything we're missing to get it to work properly? Surprised that the script mentioned in the DevOps documentation doesn't work as intended.

Azure DevOps documentation and sample script: https://docs.microsoft.com/en-us/azure/devops/pipelines/ecosystems/android?view=azure-devops#test-on-the-android-emulator



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source