简体   繁体   中英

Cordova, getting Error while adding android platform on Ubuntu 14.04

I installed cordova and can create a new project without any problems.

However I'm getting the following error when trying to add android platform:

sudo cordova platform add android
Running platform task...
Adding platform android
Creating android project...

/home/tushar/.cordova/lib/android/cordova/3.5.0/bin/node_modules/q/q.js:126
                    throw e;
                          ^
Error: An error occurred while listing Android targets
    at /home/tushar/.cordova/lib/android/cordova/3.5.0/bin/lib/check_reqs.js:87:29
    at _rejected (/home/tushar/.cordova/lib/android/cordova/3.5.0/bin/node_modules/q/q.js:808:24)
    at /home/tushar/.cordova/lib/android/cordova/3.5.0/bin/node_modules/q/q.js:834:30
    at Promise.when (/home/tushar/.cordova/lib/android/cordova/3.5.0/bin/node_modules/q/q.js:1079:31)
    at Promise.promise.promiseDispatch (/home/tushar/.cordova/lib/android/cordova/3.5.0/bin/node_modules/q/q.js:752:41)
    at /home/tushar/.cordova/lib/android/cordova/3.5.0/bin/node_modules/q/q.js:574:44
    at flush (/home/tushar/.cordova/lib/android/cordova/3.5.0/bin/node_modules/q/q.js:108:17)
    at process._tickCallback (node.js:415:13)
Error: /home/tushar/.cordova/lib/android/cordova/3.5.0/bin/create: Command failed with exit code 8
    at ChildProcess.whenDone (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/cordova/superspawn.js:131:23)
    at ChildProcess.EventEmitter.emit (events.js:98:17)
    at maybeClose (child_process.js:743:16)
    at Process.ChildProcess._handle.onexit (child_process.js:810:5)
Unable to add platform android. Please see console for more info.

I have tried almost all of the solutions from stackoverflow but none of them solved. I have added the path to android sdk, ant etc on ./bashrc file as following:

export HOME="/home/tushar"
export ANDROID_HOME="$HOME/Development/adt-bundle/sdk/tools"
export ANDROID_PLATFORM_TOOLS="$HOME/Development/adt-bundle/sdk/platform-tools"
export PATH="$ANDROID_HOME:$ANDROID_PLATFORM_TOOLS:$PATH"

export ANT_HOME="$HOME/Development/ant"
export PATH="$PATH:$ANT_HOME/bin"

But I am still getting the problem.

Any Suggestions???

UPDATE

These might be helpful to debug:

$ node -v
v0.10.25

$ npm -v
1.3.10

$ cordova -v
3.5.0-0.2.4

$ android list targets
Available Android targets:
----------
id: 1 or "android-19"
     Name: Android 4.4.2
     Type: Platform
     API level: 19
     Revision: 3
     Skins: HVGA, WXGA800, WVGA800 (default), WQVGA432, WXGA800-7in, WXGA720, QVGA, WVGA854, WQVGA400, WSVGA
 Tag/ABIs : default/armeabi-v7a

There is a problem with your paths: ANDROID_HOME should point to sdk folder, not sdk/tools

Also add ANDROID_TOOLS pointing to sdk/tools

All in all you need: JAVA_HOME, ANT_HOME, ANDROID_HOME, ANDROID_PLATFORM_TOOLS, ANDROID_TOOLS, and maybe ANDROID_SDK_ROOT pointing to sdk as well.

PS and without sudo, yes.

我认为你不必以超级用户身份执行“cordova platform add android”。

i struggled with the same issue all day.. it turned out i did not add the full path while exporting path variables...

a "shell" hand in our group suggested to run "pwd" to get the "present working directory" and then give export the exact path...it worked

Had the same problem. My PATH was correct. No problems with access rights. Also noted that the adt-emulator was running into an error.

In the end, it was missing libraries to allow the adt (which partially is 32 bit) to run on a 64 bit ubuntu system.

sudo apt-get install lib32z1 lib32z1-dev

resolved this and everything works.

Hope this helps to resolve this issue for other folks.

Had exactly the same problem in LMDE and as answered by Ranunculus, I added the below directly in my terminal and it worked!

export ANDROID_HOME="$HOME/android-sdk-linux"
export ANDROID_TOOLS="$ANDROID_HOME/tools/"
export ANDROID_PLATFORM_TOOLS="$ANDROID_HOME/platform-tools/"
export JAVA_HOME="/usr/lib/jvm/java-7-oracle"
export ANT_HOME="/usr/share/ant"
export PATH="$JAVA_HOME:$ANT_HOME:$ANDROID_HOME:$ANDROID_TOOLS:$ANDROID_PLATFORM_TOOLS:$PATH"

NB: Couldnt comment on Ranunculus's answer and so posted it as an answer.

I had the same issue (though running on Windows, but still worth checking on your side) and found out that it was due to a bug in Ant . My Classpath ended with a " too, and I had to fix this by removing the " in my class path variable.

我有同样的问题尝试硬添加多个配置冲突和另外一件事我发现我在一个终端上更新路径并尝试在另一个终端上执行Cordova命令时打开多个终端我仍然得到相同的错误所以我试图回显$ PATH在第一个终端上显示更新的路径,但另一个终端虽然回显没有显示更新的路径所以最后我打开新终端并再次启动是这次它工作,这种问题通常发生在Windows但我我不确定在Linux上是否会发生同样的情况,但就我而言,我希望这可能会帮助其他新手,因为我们的Cordova和离子指令都能正常工作,感谢SO社区的支持和指导

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM