当你将你的AVD或SDK移动到另一个目录,或用新的SDK替换旧的SDK,或以某种方式使SDK损坏时,可能会有几个不同的问题。
下面我将描述我所知道的所有可能的问题,并将为您提供几种解决它们的方法。
当然,我假设您已经创建了任何AVD,并且它位于C:\Users\<user_name>\。android\avd (Windows)或~/。安卓/ avd (Linux / MacOS)。
如果你将。android移动到另一个地方,然后将ANDROID_SDK_HOME环境变量设置为包含你的。android的父目录的路径,并确保AVD管理器成功找到你的虚拟设备。
还要检查<user_home>/.android/avd/<avd_name>.ini中的路径
不完整/损坏的SDK结构
PANIC: Cannot find AVD system path. Please define ANDROID_SDK_ROOT
PANIC: Broken AVD system path. Check your ANDROID_SDK_ROOT value
如果模拟器无法找到SDK,或者SDK损坏,就会发生这两个错误。
因此,首先我建议完全删除ANDROID_SDK_ROOT变量。只有当模拟器位于SDK目录之外时才需要它。但通常情况下,模拟器位于SDK目录中。在这种情况下,它必须自动检测SDK位置。如果没有,那么您的SDK可能有错误的文件树。请做到以下几点:
Check that the SDK directory has at least these 4 directories: emulator, platforms, platform-tools, system-images. It is very important! These directories must be present. If some of them don't exist, then just create empty dirs.
Go to <user_home>/.android/avd/<avd_name> and open config.ini. Find the image.sysdir.1 property. It points at the directory, inside the SDK directory, that contains the actual system image. Make sure that this directory exists and contains files like build.prop, system.img, etc. If it doesn't, then you have to open the SDK Manager and download system images your AVD requires (see below).
如果一切设置正确,当这些关于ANDROID_SDK_ROOT的错误必须消失时。如果不是,那么现在你可以尝试设置ANDROID_SDK_ROOT变量。
未安装所需软件包和HAXM
您可能面临的下一个问题是模拟器开始启动,但立即挂断或退出。这可能意味着您没有安装所有必需的软件包。
另一个可能的错误是:
无法自动检测到ADB二进制文件。在扩展设置页面中添加自定义的ADB路径之前,一些模拟器功能将无法工作。
所以,要成功启动任何AVD,你必须确保至少安装了这些包:
emulator (Android Emulator)
platform-tools (Android SDK Platform-Tools)
tools (Android SDK Tools)
正如我前面提到的,你必须安装你的AVD正在使用的系统镜像,例如system-images;android-25;google_apis;x86
注意,SDK的最新版本没有独立的SDK Manager.exe。相反,你必须使用Android Studio或tools\bin\sdkmanager.bat (Linux/MacOS可能有sh文件)。
要列出所有可用的包,请使用sdkmanager——list或sdkmanager——list——verbose
安装包时使用sdkmanager <package1> <package2>…
我还建议在您的系统上手动安装HAXM。
Qcow2-files指的是不正确的/不存在的base-image
我要提到的最后一个问题发生在你试图将AVD或SDK从一台计算机或目录移动到另一台计算机或目录时。在这种情况下,你可能会得到这样的错误:
qemu-system-i386.exe: -drive if=none,重叠检查=none,cache=unsafe,index=0,id=system,file=C:\Users\<old_user_name>\.android\avd\<avd_name>。
avd \ system.img。qcow2,只读:无法打开备份文件:无法打开'<old_sdk_dir>\system-images\android-22\google_api \x86\system。img':无效参数
有两种方法可以解决这个问题:
If you don't care about the data the AVD contains, just delete all the qcow2 files from the AVD directory (e.g. from <user_home>/.android/avd/<avd_name>). In this case you will get a clean version of Android, like after a hard reset.
If the data on the emulator is important to you, then open all qcow2 files one by one using any HEX editor (I prefer HxD), find the path of a base img file, and change it to the correct one in the Overwrite mode (to preserve the file size). Then select the path and get its length in hex (e.g. 2F). 2F represents the ASCII slash /. Put it into position 13:
PS:不确定,但可能有一些实用程序,如qemu-img,允许设置不同的基本图像。嗯,对我来说,手动编辑二进制文件更容易。
现在你可能可以成功启动你的Android虚拟设备了。我希望如此。