14

I get the following error while adding the Android platform. I had checked my ant -version and it outputted it correctly. Also, I noticed when it created the myApp folder node_modules wasn't fetched with it. Beneath is output from my console:

Adding platform android
Creating android project...

C:\Users\user\.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 C:\Users\user\.cordova\lib\android\cordova\3.5.0\bin\lib\check_reqs.js
:87:29
    at _rejected (C:\Users\user\.cordova\lib\android\cordova\3.5.0\bin\node_m
odules\q\q.js:808:24)
    at C:\Users\user\.cordova\lib\android\cordova\3.5.0\bin\node_modules\q\q.
js:834:30
    at Promise.when (C:\Users\user\.cordova\lib\android\cordova\3.5.0\bin\nod
e_modules\q\q.js:1079:31)
    at Promise.promise.promiseDispatch (C:\Users\Riliwan\.cordova\lib\android\co
rdova\3.5.0\bin\node_modules\q\q.js:752:41)
    at C:\Users\user\.cordova\lib\android\cordova\3.5.0\bin\node_modules\q\q.
js:574:44
    at flush (C:\Users\user\.cordova\lib\android\cordova\3.5.0\bin\node_modul
es\q\q.js:108:17)
    at process._tickCallback (node.js:419:13)
Error: C:\Users\user\.cordova\lib\android\cordova\3.5.0\bin\create.bat: Comma
nd failed with exit code 8
    at ChildProcess.whenDone (C:\Users\Riliwan\AppData\Roaming\npm\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:753:16)
    at Process.ChildProcess._handle.onexit (child_process.js:820:5)
Unable to add platform android. Please see console for more info.
Tomislav Stankovic
  • 3,080
  • 17
  • 35
  • 42
Riliwan Balogun
  • 308
  • 1
  • 2
  • 10

1 Answers1

27

I'm using Ubuntu 14.04 and fixed it by setting these paths to the O.S. Path:

export ANDROID_HOME=/home/coutinho/android-sdk 
export ANDROID_TOOLS=/home/coutinho/android-sdk/tools/  
export ANDROID_PLATFORM_TOOLS=/home/coutinho/android-sdk/platform-tools/

PATH=$PATH:$ANDROID_HOME:$ANDROID_TOOLS:$ANDROID_PLATFORM_TOOLS:.

Then it worked fine.

Rafael Coutinho
  • 523
  • 5
  • 11
  • Thanks rafael! i also noticed i needed to install an android SDK from your answer – Riliwan Balogun Jun 02 '14 at 00:21
  • 1
    I have added those paths but still getting problems. I'm on Ubuntu 14.04. – Tushar Khatiwada Jun 16 '14 at 03:48
  • 2
    +1 . I have 12.04 and I had added ANDROID_TOOLS and ANDROID_PLATFORM_TOOLS , but adding ANDROID_HOME did the job for me. Strange, it is not mentioned in official instructions. – Shrey Jun 17 '14 at 10:25
  • Even me having the same problems with different error http://stackoverflow.com/questions/24580966/error-the-command-android-failed-using-cordova – TechSpellBound Jul 28 '14 at 13:15
  • I have to add ant after also. – ThiagoPonte Sep 12 '14 at 20:11
  • Above answer, plus setting JAVA_HOME per http://stackoverflow.com/a/663726/948073 , worked for me. – Lori Sep 30 '14 at 05:52
  • In fact, you don't need to export `ANDROID_TOOLS` neither `ANDROID_PLATFORM_TOOLS`. Just setting `ANDROID_HOME` and updating `PATH` worked for me. – Caumons Dec 30 '14 at 11:46
  • Another issue could be if you are using sudo with cordova, then the exports won't work. If that's your case, try executing cordova/ionic without sudo for building. – Rafael Coutinho Jan 06 '15 at 14:27