Android模拟器30.4.5不适用于MacOS
系统信息
MacOs 版本 - 11.3 测试版
Android Studio 版本 - 4.1.2
Android 模拟器版本 - 30.4.5
Android HAXM 版本 - 7.5.1
错误堆栈
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 模拟器版本 - 30.0.26 按预期完美运行。但是在 30.4.5.0 更新后它不起作用。
我试图搜索降级到 30.0.26 的方法,但我找不到一个,即 android studio manager 中也没有任何选项。
我看到了这个SO 帖子。Google 将所有模拟器版本存储在存储库 URL - http://dl.google.com/android/repository/ 中,但我不知道 30.0.26 版本的构建版本,所以不能这样做。
更新 -
请按照下面接受的答案进行操作并投票。
对于新手或如果您在任何时候卡住,请按照以下步骤操作:
-
如果您已经卸载了最新版本的模拟器,因为它不起作用,请重新安装。(因为如果我们手动替换模拟器目录,Android Studio 将无法识别它,因此您将无法从 Android Studio 创建/运行 AVD)
-
从答案中提到的 URL 下载 zip 文件。
-
将内容复制(不移动)到您的原始模拟器目录。
-
如果需要,重新启动 android studio。
这仍然只是一种解决方法,这个新版本的实际问题仍然存在。
回答
这是模拟器修订版 30.0.26 https://dl.google.com/android/repository/emulator-darwin-6885378.zip的链接
(取自此答案)
下载它,然后复制已安装的模拟器。
如果您启用了文件隔离,它将无法工作;我这样做了,我需要从下载的文件中递归删除隔离区
xattr -r -d com.apple.quarantine /path/to/dir
然后我可以通过调用来运行模拟器:
emulator @device_name
它似乎没有被 AS 检测到,但仍然有效。
回答
下面是一个临时修复。
错误:
无法添加库/Users//Library/Android/sdk/emulator/qemu/darwin-x86_64/lib64/vulkan/libvulkan.dylib:失败
错误消息中指定的路径中似乎不存在 dylib 文件。但是,该库存在于以下路径中:
~/Library/Android/sdk/emulator/lib64/vulkan/libvulkan.dylib
将 vaulkan lib 符号链接到路径模拟器正尝试从以下位置加载库:
ln -s ~/Library/Android/sdk/emulator/lib64 ~/Library/Android/sdk/emulator/qemu/darwin-x86_64/lib64
错误 2:然后我收到了与代码签名相关的错误。
HVF 错误:HV_ERROR qemu-system-x86_64:无法初始化 HVF:参数无效
修复代码签名错误:
第 1 步:创建用于代码签名的 app.entitlements 文件并添加以下内容(来源: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>
第 2 步:执行协同设计:
codesign -s - --entitlements ~/<path>/<to>/app.entitlements --force ~/Library/Android/sdk/emulator/qemu/darwin-x86_64/qemu-system-x86_64
启动模拟器:
~/Library/Android/sdk/emulator/emulator -avd Pixel_4_API_30 -gpu auto
模拟器应该加载没有任何错误。希望这有帮助。
更新:当前版本的模拟器中不再存在此问题。请参阅@channe 的评论以在升级 AS/模拟器后恢复更改。
- Initial issue seems to be fixed in 30.5.6. If you had used above fix, uninstall and reinstall back emulator from sdk manager. This will revert the changes.
-
The issue still exists on `30.5.6` and the this solution doesn't work in that version anymore: `ERROR: qt_setup.cpp:31: Qt library not found at /Users/example/Library/Android/sdk/emulator/lib64/qt/lib`;;;`dyld: Library not loaded: @rpath/libQt5WebEngineWidgetsAndroidEmu.5.12.1.dylib
Referenced from: /Users/example/Library/Android/sdk/emulator/qemu/darwin-x86_64/qemu-system-x86_64
Reason: image not found`