Android Emulator does not start on macOs Fix
(Last Updated On: April 29, 2021)Or How to Fix android emulator HV_ERROR that triggers “The emulator process for avd was killed” problem.
I got this problem after update my macOs to Big Sur 11.3 but this can also happen in other macOs versions. After I wanted to start the emulator from Android Studio like always this popup was presented to me:
Failing Intents
I was a good couple of hours (if not more) trying to find a fix for this without success, I tried:
- Reinstall the emulator in Android Studio SDK manager
- Reinstall HAXM
- Change the emulator graphics to just software/hardware
- Update everything Android
Console output
Nothing worked. Since I did not knew what was trigger the problem I went to where the emulator executable is in my mac: ~/Library/Android/sdk/emulator
and I started the emulator manually with. ./emulator -avd Pixel_3a_API_30
. This was the output
emulator: Android emulator version 30.5.5.0 (build_id 7285888) (CL:N/A)
handleCpuAcceleration: feature check for hvf
cannot add library /Users/saninn/Library/Android/sdk/emulator/qemu/darwin-x86_64/lib64/vulkan/libvulkan.dylib: failed
added library /Users/saninn/Library/Android/sdk/emulator/lib64/vulkan/libvulkan.dylib
HVF error: HV_ERROR
qemu-system-x86_64: failed to initialize HVF: Invalid argument
HAX is working and emulator runs in fast virt mode.
qemu-system-x86_64: Back to HAX accelerator
emulator: INFO: GrpcServices.cpp:301: Started GRPC server at 127.0.0.1:8554, security: Local
The important part there is:
HVF error: HV_ERROR
qemu-system-x86_64: failed to initialize HVF: Invalid argument
After searching a little big more I found a reddit post about virtual machines where states the hidden problem:
Apple won’t let the QEMU binary run with
https://www.reddit.com/r/VFIO/comments/kdhgni/qemu_hvf_support_for_mac_os_x_bug_sur_hv_error/-accel hvf
unless the binary is signed. Every timehv_vm_create()
runs, it returns an HV_ERROR.
Finally a fix
So, that’s it! we have to manually sign the binary!
To fix the problem we have to go to where our emulator app lives, in my case I went to ~/Library/Android/sdk/emulator/qemu/darwin-x86_64
and created a new file called app.entitlements
with this content:
<?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>
After we sign it with codesign -s -- --entitlements app.entitlements --force qemu-system-x86_64
That’s it! your emulator should be working again!
Awesome post, I was having the same issue. Thanks for sharing.
nit: the signing has an extra dash
Sweet! Thanks for this fix!
“error: The specified item could not be found in the keychain.”
Something to help about this error?
Sorry, I never have seen that error before.
corret : “codesign -s – –entitlements app.entitlements –force qemu-system-x86_64″…
Try this, worked for me:
codesign -s "$(security find-identity -v -p codesigning | awk -F '"' 'NR==1{print $2}')" --entitlements app.entitlements --force qemu-system-x86_64
You’re a legend! Helped a lot thanks!!
Got an error after trying to execute codesign -s – –entitlements entitlements.xml –force qemu-system-aarch64
entitlements.xml: cannot read entitlement data
How can I fix this?