在终端中输入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虚拟设备了。我希望如此。

其他回答

看看我的答案:https://stackoverflow.com/a/60201016/12529885

尝试手动指定参数-sysdir,并检查错误消息是否改变。

他们可能打不清楚,参见源代码https://android.googlesource.com/platform/external/qemu/+/1a15692cded92d66dea1a51389a3c4b9e3b3631a/android/emulator/main-emulator.cpp

而且你可以比在网上搜索更容易解决。

if (!strcmp(opt, "-sysdir") && nn+1 < argc) {
    sysDir = argv[nn+1];
    continue;
}
// some other codes.....
if (avdName) {
    if (!isCpuArchSupportedByRanchu(avdArch)) {
        APANIC("CPU Architecture '%s' is not supported by the QEMU2 emulator, (the classic engine is deprecated!)",
               avdArch);
    }
    std::string systemPath = getAvdSystemPath(avdName, sysDir);
    if (systemPath.empty()) {
        const char* env = getenv("ANDROID_SDK_ROOT");
        if (!env || !env[0]) {
            APANIC("Cannot find AVD system path. Please define "
                   "ANDROID_SDK_ROOT\n");
        } else {
            APANIC("Broken AVD system path. Check your ANDROID_SDK_ROOT "
                   "value [%s]!\n",
                   env);
        }
    }
}

ANDROID_SDK_HOME是指向根目录的指针。该文件默认创建在“C:\Users\name\. android”目录下。android”,而不是你的SDK文件夹的根目录。然后: —将ANDROID_SDK_HOME分配到SDK根文件夹将无效。 -如果你的路”。“android”文件有非ascii字符,它将无法工作。 - AVD文件夹必须在您当前的”。android”文件。

所以答案是:

Change your SDK folder, if you need, like the previous answers (inside the project on Android Studio). Close Android Studio. Control Panel > System > Advanced System Settings > Environment Variables. Add a new User variable: Variable Name: ANDROID_SDK_HOME Variable Value: C:\src (or any folder that has not problems with non-ASCII characters or S.O. privileges) THE PATH THAT YOU WILL ENTER CANNOT BE ROOT FOLDER OF YOUR ANDROID SDK!!! Open Android Studio. Make sure a folder called ".android" was created in your new location. Delete the Android Virtual Device (AVD) that you created. Close and open Android Studio. Create a new AVD and see the magic happens.

欢呼。

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

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

echo $ANDROID_HOME && flutter doctor -v

在我的情况下,它被打破了,因为ANDROID_HOME和ANDROID_SDK_ROOT是不同的,所以一旦我设置ANDROID_HOME与ANDROID_SDK_ROOT相同,它就开始工作了。

我在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.

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