ANDROID_HOME 未设置且“android”命令不在您的 PATH Phonegap 中
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26216081/
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
ANDROID_HOME is not set and "android" command not in your PATH Phonegap
提问by Dev
i have installed android bundle and i have configured everything in .bashrc file and even when i say android in command line .. i am getting android manager .. but when i say ionic platform add android i am always getting error as "Error: ANDROID_HOME is not set and "android" command not in your PATH. You must fulfill at least one of these conditions." . i tried many way but issue not fixed .
我已经安装了 android bundle 并且我已经在 .bashrc 文件中配置了所有内容,甚至当我在命令行中说 android ..未设置且“android”命令不在您的 PATH 中。您必须至少满足这些条件之一。” . 我尝试了很多方法,但问题没有解决。
my platform :
我的平台:
Ubuntu 14.04 64 bit
Ubuntu 14.04 64 位
.bashrc file :
.bashrc 文件:
export HOME="/home/system"
export ANDROID_HOME="$HOME/adt-bundle-linux-x86_64-20140702/sdk/tools"
export ANDROID_PLATFORM_TOOLS="$HOME/adt-bundle-linux-x86_64-20140702/sdk/platform-tools"
export PATH="$ANDROID_HOME:$ANDROID_PLATFORM_TOOLS:$PATH"
export JAVA_HOME="/usr/lib/jvm/java-7-openjdk-amd64"
export ANT_HOME="/usr/share/ant"
export PATH="$ANT_HOME/bin:$PATH"
export ANDROID_HOME="/home/system/adt-bundle-linux-x86_64-20140702/sdk/tools"
error while execution :
执行时出错:
system@system-H81M-S1:/usr/share/nginx/www/myApp# ionic platform add android
npm http GET https://registry.npmjs.org/cordova-android/3.6.3
npm http 200 https://registry.npmjs.org/cordova-android/3.6.3
npm http GET https://registry.npmjs.org/cordova-android/-/cordova-android-3.6.3.tgz
npm http 200 https://registry.npmjs.org/cordova-android/-/cordova-android-3.6.3.tgz
Creating android project...
/system/.cordova/lib/npm_cache/cordova-android/3.6.3/package/bin/node_modules/q/q.js:126
throw e;
^
Error: ANDROID_HOME is not set and "android" command not in your PATH. You must fulfill at least one of these conditions.
at /system/.cordova/lib/npm_cache/cordova-android/3.6.3/package/bin/lib/check_reqs.js:158:19
at _fulfilled (/system/.cordova/lib/npm_cache/cordova-android/3.6.3/package/bin/node_modules/q/q.js:798:54)
at self.promiseDispatch.done (/system/.cordova/lib/npm_cache/cordova-android/3.6.3/package/bin/node_modules/q/q.js:827:30)
at Promise.promise.promiseDispatch (/system/.cordova/lib/npm_cache/cordova-android/3.6.3/package/bin/node_modules/q/q.js:760:13)
at /system/.cordova/lib/npm_cache/cordova-android/3.6.3/package/bin/node_modules/q/q.js:821:14
at flush (/system/.cordova/lib/npm_cache/cordova-android/3.6.3/package/bin/node_modules/q/q.js:108:17)
at process._tickCallback (node.js:419:13)
at Function.Module.runMain (module.js:499:11)
at startup (node.js:119:16)
at node.js:906:3
Error: /system/.cordova/lib/npm_cache/cordova-android/3.6.3/package/bin/
create: Command failed with exit code 8 at ChildProcess.whenDone (/usr/lib/node_modules/cordova/node_modules/
cordova-lib/src/cordova/superspawn.js:135:23)
at ChildProcess.emit (events.js:98:17)
at maybeClose (child_process.js:756:16)
at Process.ChildProcess._handle.onexit (child_process.js:823:5)
may i know how i can fix this error
我可以知道如何解决这个错误吗
回答by Indranil Mondal
I faced the same problem, and it's solved.
我遇到了同样的问题,已经解决了。
I think it's issue with the compatibility of the latest cordova with latest android. As well as you've issue with the android home path.
我认为这是最新cordova与最新android的兼容性问题。以及您对 android 主路径的问题。
In .bashrc file
在 .bashrc 文件中
export HOME="/home/indranil"
export ANDROID_HOME="$HOME/software/adt-bundle-linux-x86_64-20140702/sdk"
export PATH="$HOME/software/adt-bundle-linux-x86_64-20140702/sdk/tools:$ANDROID_HOME/platform_tools:$PATH"
Try to download the latest android SDK if you're using older version. And download Android 4.4.2(API 19) from your android manager.
如果您使用的是旧版本,请尝试下载最新的 android SDK。并从您的 android 管理器下载 Android 4.4.2(API 19)。
You can use the latest cordova (4.0.0) but if the issue is still there then use cordova (3.5.0-0.2.7), but if you want to upgrade or downgrade the cordova, remove the existing one using:-
您可以使用最新的cordova(4.0.0),但如果问题仍然存在,则使用cordova(3.5.0-0.2.7),但如果您想升级或降级cordova,请使用以下方法删除现有的:-
npm uninstall -g cordova (If linux use sudo npm uninstall -g cordova)
If you are using linux don't use sudo
如果您使用的是 linux,请不要使用 sudo
commad at the time of installing cordoava, if you get any error, run the following commands
在安装cordoava的时候用命令,如果有报错,运行以下命令
sudo chown -R `whoami` ~/.npm
sudo chown -R `whoami` /usr/local/lib/node_modules
sudo chown -R `whoami` /usr/local
Then install cordova without sudo
然后在没有sudo的情况下安装cordova
npm install -g [email protected]
At the time of creating ionic app and adding android as platform don't use sudo command. Cordova creates a .cordova directory in the home folder at the time of adding platform. Remove that directory before creating the new ionic application.
在创建 ionic 应用程序和添加 android 作为平台时,不要使用 sudo 命令。Cordova 在添加平台时会在 home 文件夹中创建一个 .cordova 目录。在创建新的离子应用程序之前删除该目录。
And after downloading the android(4.4.2), create an android virtual device using the command:
下载 android(4.4.2) 后,使用以下命令创建一个 android 虚拟设备:
android avd
回答by R_Ice
I have been struggling with this also (Ubuntu 14.04) and I remember accepting that just getting the cordova build command to work was too difficult for me :-). I was sure my PATHs were correct (tried root and user etc etc) and tried every solution I could find.
我也一直在为此苦苦挣扎(Ubuntu 14.04),我记得我接受了让cordova build命令工作对我来说太困难了:-)。我确信我的路径是正确的(尝试过 root 和用户等)并尝试了我能找到的所有解决方案。
A comment by Stoicuta Alexandru On this pagesolved it for me. I quote:
Stoicuta Alexandru在此页面上的评论为我解决了这个问题。我引用:
If ANDROID_HOME is not set, cordova will search for it in home/android-sdk
如果 ANDROID_HOME 没有设置,cordova 会在 home/android-sdk 中搜索
So just putting my android sdk in the home-folder and (important) naming it android-sdk did it.
因此,只需将我的 android sdk 放在主文件夹中,并(重要)将其命名为 android-sdk 即可。
Hope to save some people some time...
希望能救一些人一些时间...
回答by gopiariv
I had the same problem but I found an alternative method i.e. using the Phonegap Developer App. You could install it to the emulator and use it.
我遇到了同样的问题,但我找到了另一种方法,即使用Phonegap Developer App。您可以将其安装到模拟器并使用它。
回答by Mr Megamind
In my case I first created the ionic app and ran other ionic commands using SUDO; that's why it was not working as sudo uses root profile.
就我而言,我首先创建了离子应用程序并使用 SUDO 运行其他离子命令;这就是为什么它不起作用,因为 sudo 使用 root 配置文件。
This is how i fixed:
这就是我修复的方式:
delete the /home/user1/.cordova (replace user1 with you user name) i used "sudo rm" command to delete folder and all of its conents
i deleted the /home/user1/tmp folder so that when we run the cordova again it creates the new tmp folder with proper permission of current user
created new app using "ionic start app5" - this was the main issue as i previously was doing it with sudo
added platform using "ionic platform add android"
executed using "ionic run android"
删除/home/user1/.cordova(用您的用户名替换user1)我使用“sudo rm”命令删除文件夹及其所有内容
我删除了 /home/user1/tmp 文件夹,以便当我们再次运行cordova时,它会在当前用户的适当权限下创建新的tmp文件夹
使用“ionic start app5”创建了新应用程序 - 这是主要问题,因为我以前是用 sudo 做的
使用“ionic platform add android”添加平台
使用“ionic run android”执行
remember that if from command line you can run "android" command and "java -version" command then above is perfect solution. let me know if you guys need any help from me.
请记住,如果您可以从命令行运行“android”命令和“java -version”命令,那么上面是完美的解决方案。如果你们需要我的帮助,请告诉我。
回答by Didierh
After facing for many day with this issue i follow the instructions above and set my .bash_profile like this on MAC
在面对这个问题很多天后,我按照上面的说明在 MAC 上像这样设置我的 .bash_profile
#====================================================
export ANT_HOME=/usr/local/Cellar/ant/1.9.4/bin/ant
#
export HOME="/Users/User"
export ANDROID_HOME="$HOME/Downloads/Developer/adt-bundle-mac-x86_64-20140702/sdk"
export PATH="$HOME/Downloads/Developer/adt-bundle-mac-x86_64-20140702/sdk/tools:$ANDROID_HOME/platform_tools:$PATH"
#
export JAVA_HOME=$(/usr/libexec/java_home)
export PATH=${PATH}
#
export PATH=${PATH}:/Users/User/Downloads/Developer/adt-bundle-mac-x86_64-20140702/sdk/platform-tools:/Users/User/Downloads/Developer/adt-bundle-mac-x86_64-20140702/sdk/tools:/Users/User/Downloads/Developer/adt-bundle-mac-x86_64-20140702/sdk/build-tools/android-4.4W
#
NPM_PACKAGES="${HOME}/.npm-packages"
PATH="$NPM_PACKAGES/bin:$PATH"
NODE_PATH="$NPM_PACKAGES/lib/node_modules:$NODE_PATH"
#
# Unset manpath so we can inherit from /etc/manpath via the manpath
# command
unset MANPATH # delete if you already modified MANPATH elsewhere in your config
MANPATH="$NPM_PACKAGES/share/man:$(manpath)"