在终端中输入cordova运行android后,我得到了这个错误:

Waiting for emulator to start...
PANIC: Broken AVD system path. Check your ANDROID_SDK_ROOT value [/Users/username/Library/Android/sdk]!

这发生在导出之后:

export ANDROID_SDK_ROOT='/Users/username/Library/Android/sdk'

在导出之前,我得到:

Waiting for emulator to start...
PANIC: Cannot find AVD system path. Please define ANDROID_SDK_ROOT

你知道我哪里错了吗?我确定这是sdk根,所以为什么我得到破碎的avd系统路径?


当前回答

要修复或避免此问题,请确保:

You have an environment variable ANDROID_SDK_ROOT pointing to a root folder of android sdk. You have a correct file structure in the sdk folder. cmdline-tools, emulator, platform-tools, system-images, platforms should be present. If you don't have these folders you should install missing components. emulator is the emulator itself. system-images has iso images of OS to run in the emulator. platforms has platform packages required to compile an app for different APIs. platform-tools has adb and other necessary tools. Without these components the emulator wont start and will post the same error about broken avd path. Make sure that you downloaded through sdkmanager matching api versions of system image and platform. e.g. for API-30 platforms;android-30 and system-images;android-30;default;x86_64. Make sure that your avd devices are located in HOME/.android/avd. If you have custom location for avd devices you should create one more environment variable ANDROID_AVD_HOME pointing to /avd/ folder.

本文提供了所有环境变量的信息,但除了ANDROID_SDK_ROOT和ANDROID_AVD_HOME,你不需要任何其他的环境变量。

其他回答

我在Windows 10上就遇到过这个问题。 我尝试了几种解决办法,但没有一个奏效。 以下是我解决问题的方法:

Uninstalled Android Studio, SDK, .android and .AndroidStudio folders in %USERPROFILE%, Android folder in %LOCALAPPDATA%. Uninstalled Java. Downloaded latest Java JDK:https://www.oracle.com/technetwork/java/javase/downloads/jdk13-downloads-5672538.html and set PATH Environment Variable: https://docs.oracle.com/en/java/javase/11/install/installation-jdk-microsoft-windows-platforms.html#GUID-96EB3876-8C7A-4A25-9F3A-A2983FEC016A I created new Windows 10 local user using LATIN CHARACTERS with admin priviledges. Switched to the new user and installed Android Studio. When the setup wizard was shown, I selected Custom option and checked Android emulator to be installed. I left all location folders as DEFAULT.

现在我的新用户帐户一切正常。

要修复或避免此问题,请确保:

You have an environment variable ANDROID_SDK_ROOT pointing to a root folder of android sdk. You have a correct file structure in the sdk folder. cmdline-tools, emulator, platform-tools, system-images, platforms should be present. If you don't have these folders you should install missing components. emulator is the emulator itself. system-images has iso images of OS to run in the emulator. platforms has platform packages required to compile an app for different APIs. platform-tools has adb and other necessary tools. Without these components the emulator wont start and will post the same error about broken avd path. Make sure that you downloaded through sdkmanager matching api versions of system image and platform. e.g. for API-30 platforms;android-30 and system-images;android-30;default;x86_64. Make sure that your avd devices are located in HOME/.android/avd. If you have custom location for avd devices you should create one more environment variable ANDROID_AVD_HOME pointing to /avd/ folder.

本文提供了所有环境变量的信息,但除了ANDROID_SDK_ROOT和ANDROID_AVD_HOME,你不需要任何其他的环境变量。

我在模拟器更新后也遇到了同样的问题。添加变量ANDROID_AVD_HOME后问题得到解决

重要提示:路径中不能使用非ascii字符。 最后,重新安装虚拟设备或手动覆盖配置设置.ini文件中的设备路径,其中包含非ascii字符的旧路径。

C:\Users\<user_name>\.android\avd\<avd_name>

我知道它不是特定的颤振,也不是Windows操作系统,但这个线程是谷歌的第一个结果,也是这个问题的主要结果,所以:

使用windows 10并在使用Flutter时收到此错误消息,此命令起作用:

echo $ANDROID_HOME && flutter doctor -v

当你将你的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虚拟设备了。我希望如此。