Skip to content

Instantly share code, notes, and snippets.

@smaboshe
Last active August 29, 2015 14:02
Show Gist options
  • Save smaboshe/62380d4d48a32f57106f to your computer and use it in GitHub Desktop.
Save smaboshe/62380d4d48a32f57106f to your computer and use it in GitHub Desktop.
Problem adding the Android platform to a Cordova project
$ cordova platform add android
Creating android project...
/home/maximo/.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/maximo/.cordova/lib/android/cordova/3.5.0/bin/lib/check_reqs.js:87:29
at _rejected (/home/maximo/.cordova/lib/android/cordova/3.5.0/bin/node_modules/q/q.js:808:24)
at /home/maximo/.cordova/lib/android/cordova/3.5.0/bin/node_modules/q/q.js:834:30
at Promise.when (/home/maximo/.cordova/lib/android/cordova/3.5.0/bin/node_modules/q/q.js:1079:31)
at Promise.promise.promiseDispatch (/home/maximo/.cordova/lib/android/cordova/3.5.0/bin/node_modules/q/q.js:752:41)
at /home/maximo/.cordova/lib/android/cordova/3.5.0/bin/node_modules/q/q.js:574:44
at flush (/home/maximo/.cordova/lib/android/cordova/3.5.0/bin/node_modules/q/q.js:108:17)
at process._tickCallback (node.js:419:13)
Error: /home/maximo/.cordova/lib/android/cordova/3.5.0/bin/create: Command failed with exit code 8
at ChildProcess.whenDone (/usr/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:753:16)
at Process.ChildProcess._handle.onexit (child_process.js:820:5)
$ ~/.cordova/lib/android/cordova/3.5.0/bin/check_reqs
[Error: An error occurred while listing Android targets]
@smaboshe
Copy link
Author

Thanks to Stack Overflow, I managed to find a fix - http://stackoverflow.com/a/21142421

The error is because cordova did not know where to find the Android Platform and Android Platform Tools in my environment.

To fix this, define environment variable for $ANDROID_HOME and $ANDROID_PLATFORM_TOOLS. I was able to set mine in ~/.bash_profile.

Hope this helps someone.

@adaptivedev
Copy link

I still get the error, despite setting this:

For full info, see this: http://stackoverflow.com/questions/26783594/phonegap-cordova-build-android-node-modules-q-q-js-throw-e

export ANDROID_HOME="/Users/rover/Documents/Dev/adt-bundle-mac-x86_64-20140702/sdk/"
export ANDROID_PLATFORM_TOOLS="$ANDROID_HOME/platform-tools/"
export PATH="$ANDROID_HOME/build-tools/21.0.2":"$ANDROID_HOME/platform-tools/":"$ANROID_HOME/tools":"$cdba/headers":$PATH
export ANT_HOME="/usr/local/bin/ant"

$ which android
/Users/rover/Documents/Dev/Android/adt-bundle-mac-x86_64-20140702/sdk/tools/android

$which ant

/usr/local/bin/ant

ant --execdebug
exec ".../jdk1.8.0_05.jdk/..."

I'm on OSX 10.10.

Is Ant Java 1.8 ok?

Any other ideas?

@Nephilim314
Copy link

http://docs.phonegap.com/en/2.8.0/guide_getting-started_android_index.md.html#Getting%20Started%20with%20Android

Try this. It is written step by step in details. It helped me. Hope it will help you guys as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment