在终端中输入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系统路径?


当前回答

我下载了一个新的模拟器,在我的Mac电脑上解决了这个问题。

其他回答

删除使用Homebrew Android SDK作为默认SDK时的错误

和@ freak一样,我用homebrew (mac的包管理器)安装了android-sdk。我需要执行下面的操作来修复这个错误,因为我在遵循nativescript教程时遇到了这个错误。如果你像我一样打算使用android-sdk版本的brew版本使用这个答案(这将允许你使用nativescripts tns运行android api),如果你想要android工作室默认的android-sdk遵循@ freak的答案。

配置Android Studio以使用Homebrew的Android SDK

基本上你只需要在Android studio中更改Android SDK的位置。首先在android studio中打开一个项目。然后点击这个按钮打开SDK管理器。

接下来,当android SDK管理器的默认首选项出现时,你需要单击android SDK位置旁边的编辑。

查找Homebrew的Android SDK的位置

接下来,你需要在sdk组件设置屏幕上更新sdk位置,我的brew android-sdk位于这里/usr/local/share/android-sdk。你可以通过运行brew cask info android-sdk来找到你的安装位置,然后在输出的底部应该说:

You can control android sdk packages via the sdkmanager command.
You may want to add to your profile:

  'export ANDROID_SDK_ROOT="/usr/local/share/android-sdk"'

导出的ANDROID_SDK_ROOT变量的值(这里是/usr/local/share/android-sdk)是自制的android sdk的位置。

然后点击“Android SDK Location”按钮(图中标记为1),粘贴Homebrew的Android SDK位置。

然后通过安装任何包来完成向导。在这一步中,我需要删除并重新创建我的设备模拟器,但在那之后,它似乎工作得很好。

设置Android SDK环境变量指向Homebrew的Android SDK

Also you may want to make sure if you are going the Homebrew route that your profile settings script has the ANDROID_HOME and ANDROID_SDK_ROOT environment variables set to your Homebrew location of the android sdk otherwise the above won't work yet. This can get changed from the Homebrew location if you installed Homebrew before installing Android Studio as pointed out in this answer by @Jamie Armour. You can check the environment variables for the android sdk are set correctly by running echo $ANDROID_HOME and echo $ANDROID_SDK_ROOT and verifying that they both show the Homebrew location of the android sdk.

如果你需要更改ANDROID_HOME和ANDROID_SDK_ROOT值,你可以在Mac的配置文件设置中这样做,可能在~/中。~ / bash_profile。”Bashrc”,或者“~/”。并定义如下:

export ANDROID_HOME="/usr/local/share/android-sdk"
export ANDROID_SDK_ROOT="/usr/local/share/android-sdk"

You need to change the values of both the exports to the proper values of Homebrew's android SDK location then save the file. To verify that the right values have been written you should first either close and open your terminal which should rerun the file and reset the environment variables or you can source the file by running source <profile file name> where is the profile file you edited and saved. You then can rerun echo $ANDROID_HOME and echo $ANDROID_SDK_ROOT to verify that they have the Homebrew android sdk location.

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

对我来说,问题是非ASCII字符在默认路径到AVD,这在我的情况下是:

C:\Users\MY_USER.android\dept

和MY_USER包含非ASCII字符。因此,我不得不移动我的avd到其他位置和设置

ANDROID_AVD_HOME

env变量。

macOS Catalina上也有类似的问题,问题原来是我正在运行的Java版本。默认情况下,当现在安装Java时,它是版本13,这与当前版本的avd不兼容。

此外,我在安装Java 8时遇到了麻烦,所以我使用了Homebrew中提供的Java 8:

brew cask install homebrew/cask-versions/adoptopenjdk8

然后,在我的~/。我将Java版本设置为1.8:

export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)

现在可以测试avdmanager是否可以运行并检测虚拟设备(之前,这导致了一个错误,说XML不能被解析):

avdmanager list avds

我通过删除文件/usr/local/share/android-sdk解决了这个问题, 因为这个文件是我用自制软件创建的。

export ANDROID_HOME=/Users/<username>/Library/Android/sdk

export ANDROID_SDK_ROOT=/Users/<username>/Library/Android/sdk

export ANDROID_AVD_HOME=/Users/<username>/.android/avd

够了....