Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Emulator 30.4.5 not working on MacOS

System Info

MacOs Version - 11.3 Beta

Android Studio Version - 4.1.2

Android Emulator Version - 30.4.5

Android HAXM Version - 7.5.1

Error Stack

emulator: Android emulator version 30.4.5.0 (build_id 7140946) (CL:N/A)
handleCpuAcceleration: feature check for hvf
cannot add library /Users/rajaparikshit/Library/Android/sdk/emulator/qemu/darwin-x86_64/lib64/vulkan/libvulkan.dylib: failed
HVF error: HV_ERROR
qemu-system-x86_64: failed to initialize HVF: Invalid argument
Failed to open the hax module
No accelerator found.
qemu-system-x86_64: failed to initialize HAX: Operation not supported by device
added library /Users/rajaparikshit/Library/Android/sdk/emulator/lib64/vulkan/libvulkan.dylib
cannot add library /Users/rajaparikshit/Library/Android/sdk/emulator/qemu/darwin-x86_64/lib64/vulkan/libMoltenVK.dylib: failed
added library /Users/rajaparikshit/Library/Android/sdk/emulator/lib64/vulkan/libMoltenVK.dylib

Android emulator version - 30.0.26 was running perfectly as expected. But after 30.4.5.0 update its not working.

I tried to search way to downgrade to 30.0.26 but I couldn't find one i.e. there is no any option in android studio manager also.

I saw this SO post. Google store all the emulators version in repository URL - http://dl.google.com/android/repository/ but I didn't know the build version for 30.0.26 version so couldn't go this way.

Update -

Please follow the accepted answer below and do give upvote.

For newbies or if you get stuck at any point please follow the steps:

  1. If you have uninstalled the latest version of emulator as its not working, then please install it again. (Because if we manually replace the emulator directory Android Studio is not able to recognise it and hence you won't able to create/run AVD from Android Studio)

  2. Download the zip file from the URL mentioned in answer.

  3. Copy(Not Move) the content to your original emulator directory.

  4. Restart the android studio if needed.

Still this is just a workaround, actual issue with this new version is still there.

like image 361
Parikshit Chalke Avatar asked Mar 03 '21 10:03

Parikshit Chalke


People also ask

What version of Android emulator is included with Android Studio?

Android Emulator is included with Android Studio. Versions of the emulator prior to 25.3.0 were distributed as part of the Android SDK Tools. To ensure you have the latest version, check the SDK Manager for updates. For Android Emulator versions prior to 25.3.0, see the Android SDK Tools release notes.

What should I do if my Emulator is not working?

For newbies or if you get stuck at any point please follow the steps: If you have uninstalled the latest version of emulator as its not working, then please install it again. (Because if we manually replace the emulator directory Android Studio is not able to recognise it and hence you won't able to create/run AVD from Android Studio)

What's new in the Android emulator update?

This update includes support for running the emulator directly in Android Studio and virtual devices with Freeform Window Mode activated by default. The Android Emulator can now be run directly in Android Studio .

Why can't I Run my antivirus software on the Android emulator?

Some antivirus software may be incompatible with the Android Emulator. If you're using Avast software and are having trouble running the Android Emulator, try disabling Use nested virtualization when available and Enable Hardware assisted virtualization in the Avast Troubleshooting settings.


3 Answers

Here is the link for the emulator revision 30.0.26 https://dl.google.com/android/repository/emulator-darwin-6885378.zip (taken from this answer)

Download it and then copy over the installed emulator.

It won't work if you have files quarantine enabled; I did so I needed to remove quarantine recursively from downloaded files

xattr -r -d com.apple.quarantine /path/to/dir

Then I can run the emulator by invoking:

emulator @device_name

It doesn't seem to be detected by AS, but works nonetheless.

like image 54
darekxan Avatar answered Oct 22 '22 11:10

darekxan


Below is a temporary fix.

Error:

cannot add library /Users//Library/Android/sdk/emulator/qemu/darwin-x86_64/lib64/vulkan/libvulkan.dylib: failed

It seems the dylib file doesn’t exists in the path specified in the error message. However, the library exists in the path below:

~/Library/Android/sdk/emulator/lib64/vulkan/libvulkan.dylib

Symlink vaulkan lib to the path emulator is trying to load the library from:

ln -s ~/Library/Android/sdk/emulator/lib64 ~/Library/Android/sdk/emulator/qemu/darwin-x86_64/lib64

Error 2: Then I got an error related to code signing.

HVF error: HV_ERROR qemu-system-x86_64: failed to initialize HVF: Invalid argument

Fix the code signing error:
Step 1: Create the app.entitlements file for codesigning and add below content (source: https://www.reddit.com/r/VFIO/comments/kdhgni/qemu_hvf_support_for_mac_os_x_bug_sur_hv_error/):

<?xml version="1.0" encoding="utf-8"?>

    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">

    <plist version="1.0"> <dict> <key>com.apple.security.hypervisor</key> <true/> </dict> </plist>

Step 2: Perform codesign:

codesign -s - --entitlements ~/<path>/<to>/app.entitlements --force ~/Library/Android/sdk/emulator/qemu/darwin-x86_64/qemu-system-x86_64

Launch the emulator:

~/Library/Android/sdk/emulator/emulator -avd Pixel_4_API_30 -gpu auto

Emulator should load without any errors. Hope this helped.

UPDATE: This issue no longer exists in the current version of the emulator. Please refer to @channe's comment to revert the change after upgrading AS/emulator.

like image 30
Maduranga E Avatar answered Oct 22 '22 11:10

Maduranga E


I had the same issue on a Mac. I was able to fix it be updating Android Emulator to 30.6.5 from Android Studio -> Sdk Manager -> Android Sdk -> SDK Tools.
Also I had to install Intel x86 Emulator Accelerator (HAXM Installer).

like image 3
Hernán Albertario Avatar answered Oct 22 '22 12:10

Hernán Albertario