2

I'm trying to get the android platform added on cordova. I've added and downloaded the most recent SDK in Android SDK, my path is :export PATH=${PATH}:/Users/xxx/Development/android-sdk-macosx/platform-tools:Users/xxx/Development/android-sdk-macosx/tools, but I keep getting the following error:

Error: The command "android" failed. Make sure you have the latest Android SDK installed, and the "android" command (inside the tools/ folder) is added to your path.
    at /Users/xxx/.cordova/lib/android/cordova/3.5.0/bin/lib/check_reqs.js:85:29
    at _rejected (/Users/xxx/.cordova/lib/android/cordova/3.5.0/bin/node_modules/q/q.js:808:24)
    at /Users/xxx/.cordova/lib/android/cordova/3.5.0/bin/node_modules/q/q.js:834:30
    at Promise.when (/Users/xxx/.cordova/lib/android/cordova/3.5.0/bin/node_modules/q/q.js:1079:31)
    at Promise.promise.promiseDispatch (/Users/xxx/.cordova/lib/android/cordova/3.5.0/bin/node_modules/q/q.js:752:41)
    at /Users/xxx/.cordova/lib/android/cordova/3.5.0/bin/node_modules/q/q.js:574:44
    at flush (/Users/xxx/.cordova/lib/android/cordova/3.5.0/bin/node_modules/q/q.js:108:17)
    at process._tickCallback (node.js:419:13)
Error: /Users/xxx/.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.emit (events.js:98:17)
    at maybeClose (child_process.js:755:16)
    at Process.ChildProcess._handle.onexit (child_process.js:822:5)

What am I doing wrong? I've search all over for answers, but nothing seems to work. Thanks in advance!

ProGM
  • 6,949
  • 4
  • 33
  • 52
mridley1013
  • 21
  • 1
  • 5
  • check whether you have set the following paths **ANDROID_HOME**, **ANT_HOME** and Installed **Git**. Update the system PATH variable to include Android,Ant and Git directories. – frank Jul 05 '14 at 07:20
  • @frank: ANDROID_HOME and ANT_HOME environment variables are not used by the cordova project. The Android SDK tools platform tools directory must be present on the path. – Lorenzo Jul 29 '14 at 22:07
  • @frank and Lorenzo: I have ANDROID_HOME as well as ANT_HOME configured. Also, I have tools as well and platform-tools in classpath using `$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools` – TechSpellBound Jul 30 '14 at 04:50

2 Answers2

2

In case of Apache Cordova with Android Studio 0.8 for Mac OS X 10.9, if you have installed in the default /Applications folder, run this on Terminal

export ANDROID_HOME="/Applications/Android Studio.app/sdk"
export ANDROID_TOOLS="/Applications/Android Studio.app/sdk/tools/"
export ANDROID_PLATFORM_TOOLS="/Applications/Android Studio.app/sdk/platform-tools/"
PATH=$PATH:$ANDROID_HOME:$ANDROID_TOOLS:$ANDROID_PLATFORM_TOOLS

To confirm, run echo and get

echo $PATH
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Applications/Android Studio.app/sdk:/Applications/Android Studio.app/sdk/tools/:/Applications/Android Studio.app/sdk/platform-tools/

For Cordova 3.6, it threw another error on a fresh Android Studio

Error: Please install Android target "android-19"

To resolve this, open SDK manager in the IDE, and download the mentioned android version (android-19)

cforcloud
  • 589
  • 2
  • 8
1

the android command is part of the android sdk's tools package. Both android and adb are used by the Cordova tools to work their magic and both need to be put on the path.

They are located in the following directories:

path/to/android/sdk/tools
path/to/android/sdk/platform-tools  

I don't know what OS you are developing on. The process for modifying the path is different on windows and unix based systems

add to path on unix-like systems

On my system (OSX) this is done by adding the following lines to .bash_profile:

PATH=$PATH:/Users/lorenzo/dev/sdks/adt-bundle/sdk/tools
PATH=$PATH:/Users/lorenzo/dev/sdks/adt-bundle/sdk/platform-tools

this could also be done in a single line:

PATH=$PATH:/Users/lorenzo/dev/sdks/adt-bundle/sdk/tools:/Users/lorenzo/dev/sdks/adt-bundle/sdk/platform-tools

this appends the path strings to the global PATH variable. On unix the path delimiter is ':'

add to path on windows

much the same process, here is the official docs: http://msdn.microsoft.com/en-us/library/windows/desktop/ms682653%28v=vs.85%29.aspx

additional reading and next steps

This blog article will walk you through path setup, and is up to date.

You can look at the Getting Started guide for Cordova Android, which details how to add the necessary components to your path.

After your path is setup, you will need to run the android tool and install additional tools and android platforms (versions).

Your system will need Apache ANT and the java run time as well.

Note that these are not cordova specific requirements, but requirements for Android development with the SDK.

Community
  • 1
  • 1
Lorenzo
  • 413
  • 2
  • 8
  • I am developing on Ubuntu and the PATH variable has both tools and platform-tools directories added. Running command "android" from shell works fine and opens the Android SDK manager. Also, the latest version of Android SDK (infact all versions after 4.0) is installed. But somehow the script inside cordova is not able to run that command. – TechSpellBound Jul 30 '14 at 04:48
  • I'm looking into this directly with an UBUNTU VM, hopefully I can reproduce your issue. I'd appreciate it if you could drop a bug report into https://github.com/phonegap/phonegap-cli/issues – Lorenzo Jul 31 '14 at 19:32
  • I'm stuck on other related phonegap work, but this is still on my todo list – Lorenzo Aug 05 '14 at 22:29