Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android emulator boots up with black screen on microsoft hosted agent with mac-11 and Mac-12 in Azure pipeline #6152

Closed
3 of 10 tasks
snigdhadas8111 opened this issue Aug 27, 2022 · 20 comments
Assignees
Labels
bug report investigate Collect additional information, like space on disk, other tool incompatibilities etc. OS: macOS

Comments

@snigdhadas8111
Copy link

Description

I have setup a pipeline in azure devops to run automated tests using android emulator on microsoft hosted agent .For couple of days ,I can see that the emulator has been booting up with black screen.I had taken a snapshot and has been attached.The snapshot has been taken just by launching the emulator.I can see the both mac-11 and mac-12 are using new version of android emulator i.e version 31.3.10.0.

The same pipeline is running fine on mac OS-10.15 which has the older version of emulator.But mac OS-10.15 is depreciated.
screenshot1 (52)

Platforms affected

  • Azure DevOps
  • GitHub Actions

Virtual environments affected

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

Image version and build link

mac-11 and mac-12

Is it regression?

yes

Expected behavior

Android emulator Must bootup with graphics display

Actual behavior

Android emulatoe boots up with black/grey scrren

Repro steps

Setup a pipeline in azure devops to launch android emulator on microsoft hosted agent.
Take scrren shot of the desktop agent
Run the pipeline on mac-11 and mac-12

@igorboskovic3 igorboskovic3 added OS: macOS investigate Collect additional information, like space on disk, other tool incompatibilities etc. and removed needs triage labels Aug 29, 2022
@igorboskovic3
Copy link
Contributor

Hi @snigdhadas8111 we will take a look.

@snigdha81
Copy link

As mac OS-10.15 is getting depreciated, this will be blocker for us .Is this the right channel to post this issue ?.If not could you guide me to proper channel?

@igorboskovic3
Copy link
Contributor

igorboskovic3 commented Aug 30, 2022

Hi @snigdhadas8111 I will try to reproduce this issue outside of this codebase.

@igorboskovic3 igorboskovic3 self-assigned this Aug 30, 2022
@snigdhadas8111
Copy link
Author

Hi @igorboskovic3 , it would be very helpful if you can help us with your findings.

@igorboskovic3
Copy link
Contributor

Hi @snigdhadas8111, we are working on resolution, as soon as we have one, I will update it here. Btw, can you try again, since we deployed new image yesterday, thank you

@snigdha81
Copy link

Thank @igorboskovic3. Just tried and it looks issue is still there .Will wait for the update here .Here is the snapshot that has been captured
screenshot1 (59)

@igorboskovic3
Copy link
Contributor

Hi @snigdhadas8111, thank you for additional try, I wanted to confirm that you have issue on newest image.

@dsame
Copy link
Contributor

dsame commented Sep 2, 2022

Hello @snigdhadas8111
Can you please provide the step of the pipeline to launch the emulator? In order to reproduce the problem i'd like to know

  • the way the emulator is installed/updated (if not pre-installed is used)
  • the image to be used to create the AVD
  • how the AVD is created
  • and most important: how the emulator is launched and is waiting for ready status

also i assume there're no changes in the emulator config files.

@snigdha81
Copy link

snigdha81 commented Sep 5, 2022

Hi @dsame ,

Sharing the scripts used in pipeline:

task: Bash@3
displayName: Install AVD FIle
inputs:
targetType: inline
script: >+

Install AVD files

echo "y" | $ANDROID_HOME/tools/bin/sdkmanager --install 'system-images;android-27;google_apis;x86'

task: Bash@3
displayName: Create AVD
inputs:
targetType: inline
script: >-

Create emulator

echo "no" | $ANDROID_HOME/tools/bin/avdmanager create avd -n xamarin_android_emulator -k 'system-images;android-27;google_apis;x86' --force
$ANDROID_HOME/emulator/emulator -list-avds

task: Bash@3
displayName: Start Emulator
inputs:
targetType: inline
script: >2-

#!/usr/bin/env bash
echo "Starting emulator"

Start emulator in background

nohup $ANDROID_HOME/emulator/emulator -avd xamarin_android_emulator -no-snapshot &
$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'
echo "Emulator started"

Note:

Tried with all images including API Level 33.
Assuming emulator is taking more time to display the graphics ,waited a max time of 10 mins before taking screen shot.
Able to communicate with the device through adb commands .So the device has not hanged.

@dsame dsame self-assigned this Sep 5, 2022
@dsame
Copy link
Contributor

dsame commented Sep 5, 2022

@snigdhadas8111
yes, it is correct way to launch the emulator. While i am trying to reproduce and solve the problem, please try to take a look at this snippet https://gist.github.com/badsyntax/ce848ab40b952d944c496575d40e5427 - it looks we have some GPU issue which is common problem that may be solved with gpu options and/or screen settings. It might happen you will be able to find out the solution before i will do.

@snigdha81
Copy link

@dsame ,Had tried all GPU options without any success. Would like to add one note here. The same emulator configuration works on mac OS-10.15 which has the older version of emulator .Mac 11 and 12 are using the latest emulator version.

@igorboskovic3
Copy link
Contributor

Hi @snigdhadas8111, can you use this snippet for installation of Android emulator here. You can see proof of work on summary as artifacts here.
screenshot

Issue was caused by Intel Hardware Accelerated Execution Manager (HAXM) which was not installed. We have it installed on MacOS 10.15 and that was working as I know for you. Please, try this approach as a workaround and let me know results.

@snigdha81
Copy link

Hi,

With the snippet shared above ,I am able to see the display.
Thanks a lot for the support.

@igorboskovic3
Copy link
Contributor

igorboskovic3 commented Sep 12, 2022

Sharing snippet here in case I delete testing repo

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

name: android-emulator-test-macos

# 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: 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

@dsame
Copy link
Contributor

dsame commented Sep 13, 2022

@snigdha81 glad to here the provided solution worked for you, while i am closing the issue, please feel free to reopen it or create another one in case the problem appears once again.

@mrk-han
Copy link

mrk-han commented Oct 18, 2022

@igorboskovic3 https://github.com/igorboskovic3/actions-test/actions/runs/3239642296

in your latest run, if you check the PNG it is black

emulator

screenshot

@mrk-han
Copy link

mrk-han commented Oct 18, 2022

Please reference the above ^ and consider re-opening this issue

@igorboskovic3
Copy link
Contributor

@mrk-han This issue is resolved, so we wont reopen this one. That is my testing repo and I wouldnt use that as reference. Im testing there various variables and this one is not related specific to your issue. For example you can find in my testing repo this action https://github.com/igorboskovic3/actions-test/actions/runs/3239143575, which works well.

@mrk-han
Copy link

mrk-han commented Nov 10, 2022

Issue was caused by Intel Hardware Accelerated Execution Manager (HAXM) which was not installed. We have it installed on MacOS 10.15 and that was working as I know for you. Please, try this approach as a workaround and let me know results.

With the latest android emulator on macOS, HAXM is actually not needed because it defaults to the native macOS hypervisor. See: here

@mrk-han
Copy link

mrk-han commented Nov 10, 2022

Trying to install HAXM adds a pop-up about kernel extensions that further blocks tests from running.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug report investigate Collect additional information, like space on disk, other tool incompatibilities etc. OS: macOS
Projects
None yet
Development

No branches or pull requests

5 participants