ANDROID_HOME won't set and Cordova projects don't build

时间:2015-08-06 13:52:31

标签: linux cordova variables environment

Everything was working perfectly last month, my Cordova projects were building with no problems but suddenly nothing works. Not even the Cordova Hello World example. I can create a Cordova project. But when I try to build it I get errors. I'm using Ubuntu 14.04. When I try build a project with

cordova build

I get a whole bunch of acces errors

rm: could not remove file (code EACCES): and

Error: EACCES, permission denied

then when I try to build a project with sudo I get the following errors

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

and

Command failed with exit code 2. You may not have the required environment or OS to build this project

Running export in terminal doesn't solve the problem either as my android-sdk is installed in a folder called Software/android-sdk-linux and

echo $ANDROID_HOME

returns the correct path Any idea whats actually going on here. Do I really need to uninstall everything and start from scratch? say it aint so!

1 个答案:

答案 0 :(得分:0)

过去两个小时我一直在研究这个问题。不知何故,我设法让它工作。这就是我的所作所为:

  1. 运行Error: EACCES, permission denied时,我还收到了cordova build条消息。在项目目录上运行ll显示,文件夹平台插件 www 需要 root 权利。这就是我们必须使用 sudo 运行cordova build的原因。也许你和我都用sudo cordova create ...创建了这个cordova项目。试试这个:创建另一个cordova项目并检查命名文件夹是否仍需要root权限。如果是,请使用chmod进行更改。如果没有,您现在应该可以在没有 sudo 的情况下运行cordova build
  2. 确保以正确的方式添加了PATH变量。将export ANDROID_HOME=...添加到~/.bashrc~/.profile。执行后者时,请确保在编辑文件后运行source ~/.profile。否则你的bash不会注意到这些变化。最佳做法是将此添加到您的~/.bashrc

    export ANDROID_HOME=~/.../android-sdk-linux
    export PATH=$ANDROID_HOME/tools:$PATH
    export PATH=$ANDROID_HOME/platform-tools:$PATH
    
  3. 在尝试构建cordova项目之前,您应该可以在bash中运行android,因为cordova使用该命令。

  4. 希望这也适合你。