1. 现象:
Mac环境下,无法启动AndroidStudio中的Android虚拟机,AVD可启动,但相关Emulator启动最后会闪退,无法看到log。
2. 解决过程:
($ANDROID_HOME为Android Sdk路径)
cd $ANDROID_HOME
查看AVD列表:
./android list avd
结果为:
*************************************************************************
The "android" command is deprecated.
For manual SDK, AVD, and project management, please use Android Studio.
For command-line tools, use tools/bin/sdkmanager and tools/bin/avdmanager
*************************************************************************
Running /Users/afunx/Library/Android/sdk/tools/bin/avdmanager list avd
Available Android Virtual Devices:
Name: Nexus_5_API_24
Device: Nexus 5 (Google)
Path: /Users/afunx/.android/avd/Nexus_5_API_24.avd
Target: Google APIs (Google Inc.)
Based on: Android 7.0 (Nougat) Tag/ABI: google_apis/x86
Skin: nexus_5
Sdcard: 100M
命令行启动AVD(Nexus_5_API_24请替换为实际AVD Name,依据./android list avd结果):
./emulator -avd Nexus_5_API_24
结果为:
Hax is enabled
Hax ram_size 0x60000000
HAX is working and emulator runs in fast virt mode.
Failed to sync vcpu reg
Failed to sync vcpu reg
Failed to sync vcpu reg
Failed to sync HAX vcpu contextInternal error: Initial hax sync failed
google搜索"Failed to sync HAX vcpu context"到stackover:
http://stackoverflow.com/questions/17024538/how-do-i-fix-failed-to-sync-vcpu-reg-error
3. 解决方法:
关掉所有虚拟机(包括genimotion、virtualbox、docker等),即可启动Android Studio自带的虚拟机。
4. 总结:
虽然,这里的解决方法是关掉所有虚拟机。但每个人情况可能不同。在Android Studio中,无法查看AVD启动失败的log。故可通过命令行的过程,来定位具体问题。