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


当前回答

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

其他回答

你应该添加AVD模拟器。 去这个位置:

C:\Users\%username%\AppData\Local\Android\sdk\

启动AVD管理器,在第二个选项卡(设备定义)中单击“创建AVD”按钮。

在Mac OS X上,我也遇到了同样的问题。我无法从Visual Studio中启动Xamarin应用程序,但Android Studio中的原生Java Android项目在虚拟设备中可以运行。

我所做的是:

取消设置ANDROID_HOME和ANDROID_SDK_ROOT环境变量。

unset ANDROID_HOME
unset ANDROID_SDK_ROOT

移除已经崩溃的虚拟设备。我是在Visual Studio中完成的。 创建新的虚拟设备。

奥列格·切尔的回答让我找到了解决办法。正如他提到的

去/。Android /avd/打开config.ini。找到>image.sysdir。1房地产。它指向SDK中包含系统>图像的目录。确保该目录存在并包含build等文件。道具>系统。img等等。如果它没有,那么你必须打开SDK管理器和>下载系统图像你的AVD需要(见下文)。

我在avd目录中找到了相应的模拟器*.ini文件。 在那里,我修改了“image.sysdir”。1”条目。我将相对路径替换为绝对路径(在前面附加ANDROID_SDK_ROOT)。在此之后,模拟器如预期的那样从命令行启动。

在Windows 10(没有Android Studio)中,我通过传输“PANIC: Broken AVD系统路径”解决了这个问题。android的文件夹从默认位置“C:\Users\Леон”进入SDK文件夹。改变环境

ANDROID_SDK_ROOT=D:\Android\SDK
ANDROID_AVD_HOME=%ANDROID_SDK_ROOT%\.android\avd
ANDROID_EMULATOR_HOME=%ANDROID_SDK_ROOT%\.android   

我认为问题可能是在USER路径中的非ascii符号中,或者它们需要“全部放在一起”。

删除使用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.