在终端中输入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目录不能包含中文 上面这些方法我都试过了,还是报错,不知道是不是我的avd目录里有汉字。所以我改变默认的avd目录通过以下步骤,它工作。 1. 创建一个路径不包含非ascii字符的文件夹 2. 复制或剪切默认的avd文件夹$HOME/。Android在你刚刚创建的文件夹下面 3.添加PATH ADNDROID_SDK_HOME, Android工作室会在$ADNDROID_SDK_HOME/.android/avd下面找到avd

终于成功了!:>

其他回答

看看我的答案: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);
        }
    }
}

我在Mac上也遇到了同样的问题,我是这么做的:

我删除了与brew一起安装的android-sdk 我将ANDROID_HOME变量设置为ANDROID_SDK_ROOT=/Users/username/Library/Android/sdk。

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

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,你不需要任何其他的环境变量。

在Mac: 我使用brew和Android Studio安装了Android -sdk。不知何故,两次安装导致了这个问题。当我卸载我的brew安装的sdk使用brew桶卸载android-sdk,并添加以下vars到我的env。它工作。

export ANDROID_HOME=/Users/<Username>/Library/Android/sdk
export ANDROID_SDK_ROOT=$ANDROID_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.

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