cordova platform add android - Not working on Mac Os

I'm new to cordova mobile app development. I have install Node and then install cordova. i have done those steps to create a cordova android app.

  1. cordova create hello com.example.hellow HelloWorld This work fine
  2. cd hello Navigation to directory_
  3. cordova platform add android This is not working

This is the error showing my terminal

Jeys-MacBook-Pro:hello mactec$ cordova platform add android
Creating android project...

/Users/mactec/.cordova/lib/android/cordova/3.4.0/bin/node_modules/q/q.js:126
                    throw e;
                          ^
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/mactec/.cordova/lib/android/cordova/3.4.0/bin/lib/check_reqs.js:85:29
    at _rejected (/Users/mactec/.cordova/lib/android/cordova/3.4.0/bin/node_modules/q/q.js:808:24)
    at /Users/mactec/.cordova/lib/android/cordova/3.4.0/bin/node_modules/q/q.js:834:30
    at Promise.when (/Users/mactec/.cordova/lib/android/cordova/3.4.0/bin/node_modules/q/q.js:1079:31)
    at Promise.promise.promiseDispatch (/Users/mactec/.cordova/lib/android/cordova/3.4.0/bin/node_modules/q/q.js:752:41)
    at /Users/mactec/.cordova/lib/android/cordova/3.4.0/bin/node_modules/q/q.js:574:44
    at flush (/Users/mactec/.cordova/lib/android/cordova/3.4.0/bin/node_modules/q/q.js:108:17)
    at process._tickCallback (node.js:415:13)
Error: /Users/mactec/.cordova/lib/android/cordova/3.4.0/bin/create: Command failed with exit code 8
    at ChildProcess.whenDone (/usr/local/lib/node_modules/cordova/src/superspawn.js:126: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)
Jeys-MacBook-Pro:hello mactec$ 

Please help me to short-out this issue

Thanks in advance.

Upvotes: 2

Views: 6009

Answers (3)

Scott
Scott

Reputation: 39

There's also another potential cause for this error: an errant file in your project/www directory. I had inadvertently included a blank file called project/www/:q ("colon q") in www/ (note I use Vim)! Anyway, doing this yields the exact error as noted by JeyTheva. So, delete that file and do the following:

  • cordova platform remove android
  • rm -r ~/.cordova/lib/android
  • cordova platform add android

Now rebuild and run on your device. This should work if you did something similar to what I did.

Upvotes: 1

The problem is PATH wrongly defined on .bash_profile.

What i have done for this.

  1. Change the path on bash profile open ~/.bash_profile. Then the bash profile open in a text editor.
  2. Add the correct path to android SDK. If we have android studio then the path is /Application/Android Studio.app/sdk/ so we need to add this path to .bash_profile. export PATH=${PATH}:/Applications/Android\ Studio.app/sdk/tools
  3. Then close all terminal and open again and code... :)

You can check that is working or not via typing android on terminal.

Upvotes: 4

ShinyJos
ShinyJos

Reputation: 1487

The error show in quite clear.You have to have the android sdk installed and proper path set in the system variable for the SDK, for cordova to work.See the prerequisites in cordova documentation http://cordova.apache.org/docs/en/3.0.0/guide_cli_index.md.html.For cordova 3.4 project android SDK must have target 19 installed.

Download SDK here http://developer.android.com/sdk/index.html

Here is the platform guide for more information http://cordova.apache.org/docs/en/3.0.0/guide_platforms_android_index.md.html#Android%20Platform%20Guide

If you already have the SDK installed,check to see if the path is refered properly for cordova to find

Upvotes: 1

Related Questions