6
votes

http://cordova.apache.org/docs/en/3.3.0/guide_platforms_android_index.md.html#Android%20Platform%20Guide

As metioned in the above doc, I have already installed the required software for Phonegap as I have getting versions:

For Java:

$ java -version java version "1.7.0_51" Java(TM) SE Runtime

Environment (build 1.7.0_51-b13) Java HotSpot(TM) 64-Bit Server VM
(build 24.51-b03, mixed mode)

For ANT

$ ant -version

Apache Ant(TM) version 1.8.2 compiled on December 3
2011

For Node.JS

$ npm -version

1.4.3

Now, the problem is when I create a phonegap project for Android like this "$ cordova create hello com.example.hello HelloWorld", it creates the project directory with "hello" name.

But now, when I enter this command "$ cordova platform add android" in "hello" directory, it gives me the error given below:

/hello$ cordova platform add android Creating android project...

/home/deep/.cordova/lib/android/cordova/3.4.0/bin/node_modules/q/q.js:126 throw e; ^ Error: An error occurred while listing Android targets at /home/deep/.cordova/lib/android/cordova/3.4.0/bin/lib/check_reqs.js:87:29 at _rejected (/home/deep/.cordova/lib/android/cordova/3.4.0/bin/node_modules/q/q.js:808:24) at /home/deep/.cordova/lib/android/cordova/3.4.0/bin/node_modules/q/q.js:834:30 at Promise.when (/home/deep/.cordova/lib/android/cordova/3.4.0/bin/node_modules/q/q.js:1079:31) at Promise.promise.promiseDispatch (/home/deep/.cordova/lib/android/cordova/3.4.0/bin/node_modules/q/q.js:752:41) at /home/deep/.cordova/lib/android/cordova/3.4.0/bin/node_modules/q/q.js:574:44 at flush (/home/deep/.cordova/lib/android/cordova/3.4.0/bin/node_modules/q/q.js:108:17) at process._tickCallback (node.js:415:13) Error: /home/deep/.cordova/lib/android/cordova/3.4.0/bin/create: Command failed with exit code 8 at ChildProcess.whenDone (/usr/lib/node_modules/cordova/src/superspawn.js:112: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)

How to get out of this problem?

5

5 Answers

7
votes

I could fix this issue by following the cordova-guide. in short:

  1. download the adt-bundle
  2. unzip it to a location of my choice
  3. add the named folders to the PATH variable:

    export PATH=${PATH}:/home/me/opt/adt-bundle/sdk/platform-tools:/home/me/opt/adt-bundle/sdk/tools

6
votes

hey man if you are using windows then you are missing environment variables. try this for this error: "An error ocurred while listing Android targets"

  1. go to My computer - right click - properties - advance system settings - environment variables.

  2. add some variables needed, I did it like this

examples using my local scenario:

SDKHOME -> C:\development\AndroidADTBundle\ADT\sdk JAVAJDK-> C:\Program Files\Java\jdk1.8.0_05\

  1. Then update the PATH variable Like this: ";%SDKHOME%\tools;%SDKHOME%\platform-tools;%JAVAJDK%\bin"

After doing then do your command, in my case is phonegap instead of cordova. And it should work: COMMAND: phonegap build android

let me know how it goes.

4
votes

I had the same problem, none of the previous anwsers works for me. The problem is that phonegap is not compatible with Android API 20.

First make sure you have setted all environment variables nedded:

export ANT_HOME=/usr/share/ant
export JAVA_HOME="/usr/lib/jvm/java-7-openjdk-amd64"
export PATH=${PATH}:~/sdk/adt-bundle-linux-x86_64-20140702/sdk/platform-tools/:~/adt/adt-bundle-linux-x86_64-20140702/sdk/tools:$JAVA_HOME/bin:$ANT_HOME/bin

Go to the shell and run android, once there, check the API 19 and install it:

$ android

Now create a device from android avd using API 19 you have downloaded before:

$ android avd

Now try to add the platform to cordova:

$ cordova platform add android

Or check the requirements using cordova check script (~/.cordova/lib/android/cordova/3.5.0/bin/check_reqs)

2
votes

Have you downloaded the Android SDK?

try typeing the command 'android' in command-line or terminal

See the answer I typed out here:

answer

0
votes

try this one

install ant using brew

Download and install Homebrew by executing following command in terminal:

ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"

Install Apache Ant via Homebrew by executing

brew install ant

Run the PhoneGap build again and it should successfully compile and install your Android app.