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:
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
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 184.108.40.206 (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 withhttps://www.reddit.com/r/VFIO/comments/kdhgni/qemu_hvf_support_for_mac_os_x_bug_sur_hv_error/
-accel hvfunless the binary is signed. Every time
hv_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:
<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!