错误:ANDROID_HOME 未设置且“android”命令不在您的 PATH 中。您必须至少满足这些条件之一。

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26356359/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 11:18:09  来源:igfitidea点击:

Error: ANDROID_HOME is not set and "android" command not in your PATH. You must fulfill at least one of these conditions.

androidwindowsmacoscordova

提问by rrvasanth

I'm trying to install PhoneGap and I'm getting the following error:

我正在尝试安装 PhoneGap,但出现以下错误:

Error: ANDROID_HOME is not set and "android" command not in your PATH. You must fulfill at least one of these conditions.

错误:ANDROID_HOME 未设置且“android”命令不在您的 PATH 中。您必须至少满足这些条件之一。

Error (screenshot)

错误(截图)

enter image description here

在此处输入图片说明

What do I do to ensure Android is set up correctly for use with Cordova?

我该怎么做才能确保正确设置 Android 以便与 Cordova 一起使用?

回答by mach

For Windows:

对于 Windows:

set ANDROID_HOME=C:\ installation location\android-sdk

set PATH=%PATH%;%ANDROID_HOME%\tools;%ANDROID_HOME%\platform-tools

设置 ANDROID_HOME=C:\安装位置\android-sdk

设置 PATH=%PATH%;%ANDROID_HOME%\tools;%ANDROID_HOME%\platform-tools

Taken from this installation guide.

取自本安装指南

回答by Ankur Tiwari

For Mac OS X:

对于 Mac OS X:

export ANDROID_HOME=/<installation location>/android-sdk-macosx
export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools

回答by lgm

I have MAC OS X Yosemite, Android Studio 1.0.1, JDK 1.8, and Cordova 4.1.2

我有 MAC OS X Yosemite、Android Studio 1.0.1、JDK 1.8 和 Cordova 4.1.2

When I tried to add the android project:

当我尝试添加 android 项目时:

cordova platforms add android

I received the message: ANDROID_HOME is not set and "android" command not in your PATH

我收到消息: ANDROID_HOME 未设置且“android”命令不在您的 PATH 中

Based in cforcloud's answer... 'Error: the command "android" failed' using cordovaand http://developer.android.com/sdk/installing/index.html?pkg=studioI used the following:

基于 cforcloud 的回答...... 使用cordovahttp://developer.android.com/sdk/installing/index.html?pkg=studio的'错误:命令“android”失败'我使用了以下内容:

export ANDROID_HOME="/Users/<user_name>/Library/Android/sdk"
export ANDROID_TOOLS="/Users/<user_name>/Library/Android/sdk/tools/"
export ANDROID_PLATFORM_TOOLS="/Users/<user_name>/Library/Android/sdk/platform-tools/"
PATH=$PATH:$ANDROID_HOME:$ANDROID_TOOLS:$ANDROID_PLATFORM_TOOLS
echo $PATH

When I tried to create the android project, I received this message:

当我尝试创建 android 项目时,收到此消息:

Creating android project...
/Users/lg/.cordova/lib/npm_cache/cordova-android/3.6.4/package/bin/node_modules/q/q.js:126
                    throw e;
                          ^
Error: Please install Android target "android-19".

I ran Android SDK Manager, and installed Android 4.4.2 (API 19) (everything but Glass Development Kit Preview). It worked for me.

我运行了 Android SDK Manager,并安装了 Android 4.4.2 (API 19)(除了 Glass Development Kit Preview 之外的所有东西)。它对我有用。

===

===

This is the content of my .bash_profile file.

这是我的 .bash_profile 文件的内容。

export PATH=$PATH:/usr/local/bin
export JAVA_HOME=`/usr/libexec/java_home -v 1.8`
launchctl setenv STUDIO_JDK /library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk
export ANDROID_HOME="/Users/<UserName>/Library/Android/sdk"
export ANDROID_TOOLS="/Users/<UserName>/Library/Android/sdk/tools"
export ANDROID_PLATFORM_TOOLS="/Users/<UserName>/Library/Android/sdk/platform-tools"
PATH=$PATH:$ANDROID_HOME:$ANDROID_TOOLS:$ANDROID_PLATFORM_TOOLS

To edit .bash_profile using Terminal, I use nano. It is easy to understand.

要使用终端编辑 .bash_profile,我使用 nano。这很容易理解。

cd
nano .bash_profile

I hope it helps.

我希望它有帮助。

回答by hash

for windows:

对于窗户:

Right click on My computer -> properties -> Advanced system setting -> Environment Variables Edit Path on system variables to ;\yourSdkHome\tools;\yourSdkHome\platform-tools.

右键单击我的电脑 -> 属性 -> 高级系统设置 -> 环境变量 系统变量上的编辑路径为 ;\yourSdkHome\tools;\yourSdkHome\platform-tools。

Then Close your cmd prompt and reopen.

然后关闭您的 cmd 提示符并重新打开。

Thats it.

就是这样。

回答by Quique

On Linux, add this to the end of your .bashrc, .profile or appropriate file for your shell:

在 Linux 上,将此添加到 .bashrc、.profile 或适用于您的 shell 的相应文件的末尾:

export ANDROID_HOME=/home/youruser/whatever/adt-bundle-linux-x86_64-20140702/sdk
export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platforms-tools

Please notice that these environment variables will be available for newly created shells, not the already open.

请注意,这些环境变量可用于新创建的 shell,而不是已打开的 shell。

回答by carlosperate

Using Android Studio on Windows the system variables settings have changed a little.

在 Windows 上使用 Android Studio,系统变量设置发生了一些变化。

You still have to add a system variable ANDROID_HOME, but pointing to the directory containing the android SDK usually installed in C:\Users\YOUR_USERNAME\AppData\Local\Android\android-studio\sdk.

您仍然需要添加一个系统变量ANDROID_HOME,但要指向包含通常安装在C:\Users\YOUR_USERNAME\AppData\Local\Android\android-studio\sdk.

You also need to add the following to the Pathsystem variable:

您还需要将以下内容添加到Path系统变量中:

;%ANDROID_HOME%\platform-tools;%ANDROID_HOME%\tools;

;%ANDROID_HOME%\platform-tools;%ANDROID_HOME%\tools;

Taken from: https://github.com/simnova/webdevdocs/wiki/Installing-PhoneGap-and-Android-Studio-on-Windows

摘自:https: //github.com/simnova/webdevdocs/wiki/Installing-PhoneGap-and-Android-Studio-on-Windows

SDK Path also be in C:\Users\USER\AppData\Local\Android\sdk

SDK路径也在 C:\Users\USER\AppData\Local\Android\sdk

回答by kangkyu

This is what I just tried to make it work. I was in:

这就是我试图让它发挥作用的方法。我是在:

os x Yosemite version 10.10.2
cordova version 4.2.0
android studio 1.0.1
Java SE Development Kit 7

os x Yosemite 版本 10.10.2
科尔多瓦版本 4.2.0
android studio 1.0.1
Java SE 开发工具包 7

set path:

设置路径:

# on ~/.zshrc file (open a text editor)
export ANDROID_HOME="/Users/<user>/Library/Android/sdk/"
export ANDROID_TOOLS="/Users/<user>/Library/Android/sdk/tools"
export ANDROID_PLATFORM_TOOLS="/Users/<user>/Library/Android/sdk/platform-tools"
PATH=$PATH:$ANDROID_HOME:$ANDROID_TOOLS:$ANDROID_PLATFORM_TOOLS

reopen terminal

重新打开终端

install "android-19" from android SDK manager

从 android SDK 管理器安装“android-19”

$ android
# pick "SDK Platform Android 4.4.2, API 19"

and then go to a Cordova-based project directory

然后转到基于 Cordova 的项目目录

$ ionic platform add android

回答by Milap Jethwa

Android path set in linux:

$export ANDROID_HOME=/usr/lib/android-sdk-linux
$export PATH=$PATH:$ANDROID_HOME/tools
$export PATH=$PATH:$ANDROID_HOME/platforms-tools

than

$cordova run android

回答by Mohammed Safeer

In Linux,

在 Linux 中,

edit .bashrcfile and add the ANDROID_HOMEand PATHvariable,

编辑.bashrc文件并添加ANDROID_HOMEPATH变量,

export ANDROID_HOME=/usr/local/android-sdk-linux/
export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platforms-tools

After saving .bashrcfile, run

保存.bashrc文件后,运行

source ~/.bashrc

then in type

然后输入

androidin a terminal

android在一个终端

if it will run, ANDROID_HOMEand PATHis set,

如果它会运行ANDROID_HOMEPATH设置,

if you get this message,

如果你收到这条消息

bash: /src/android-sdk/tools/android: Permission denied

then run

然后运行

sudo chmod a+x /usr/local/android-sdk-linux/tools/android

otherwise you will get same error message

否则你会得到同样的错误信息

Error: Android SDK not found. Make sure that it is installed. If it is not at the default location, set the ANDROID_HOME environment variable.

NB: Use your android sdk installation path instead of /usr/local/android-sdk-linux/

注意:使用您的 android sdk 安装路径而不是 /usr/local/android-sdk-linux/

回答by xleon

For Windows I just had to add an env variable pointing to the SDK folder. Done! (The accepted answer didn′t work for me)

对于 Windows,我只需要添加一个指向 SDK 文件夹的 env 变量。完毕!(接受的答案对我不起作用)

enter image description here

在此处输入图片说明