Andrej Kaurin
Andrej Kaurin

Reputation: 11642

Cordova for android: An error occurred while listening android targets

I have read all the questions for the same problems and I have tried everything but nothing is working for me when I try to add android platform for cordova.

c:\Apps\fapp>cordova platform add android
Creating android project...

C:\Users\Andrej\.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 C:\Users\Andrej\.cordova\lib\android\cordova\3.4.0\bin\lib\check_reqs.js:
87:29
    at _rejected (C:\Users\Andrej\.cordova\lib\android\cordova\3.4.0\bin\node_mo
dules\q\q.js:808:24)
    at C:\Users\Andrej\.cordova\lib\android\cordova\3.4.0\bin\node_modules\q\q.j
s:834:30
    at Promise.when (C:\Users\Andrej\.cordova\lib\android\cordova\3.4.0\bin\node
_modules\q\q.js:1079:31)
    at Promise.promise.promiseDispatch (C:\Users\Andrej\.cordova\lib\android\cor
dova\3.4.0\bin\node_modules\q\q.js:752:41)
    at C:\Users\Andrej\.cordova\lib\android\cordova\3.4.0\bin\node_modules\q\q.j
s:574:44
    at flush (C:\Users\Andrej\.cordova\lib\android\cordova\3.4.0\bin\node_module
s\q\q.js:108:17)
    at process._tickCallback (node.js:415:13)
Error: cmd: Command failed with exit code 8
    at ChildProcess.whenDone (C:\Users\Andrej\AppData\Roaming\npm\node_modules\c
ordova\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)

I really tried everything but keeps throwing this problem.

EDIT:

FINAL SOLUTION

Upvotes: 6

Views: 11238

Answers (5)

sivi
sivi

Reputation: 11144

This link http://spring.io/guides/gs/android/ + running cmd as an administrator solved that issue for me.

This confirms Michael Brooks' assumption that this issue has to do with permissions settings on the Windows OS. https://github.com/phonegap/phonegap-cli/issues/77

Upvotes: 0

dwettstein
dwettstein

Reputation: 687

I had the same issue with version 3.5.0.

The problem is, that the error message from the script check_reqs located in C:\Users\{yourUserName}\.cordova\lib\android\cordova\3.5.0\bin, is not forwarded correctly.

I run the mentioned script manually and got the following error message:

[Error: Please install Android target 19 (the Android newest SDK). Make sure you have the latest Android tools installed as well. Run "android" from your command-line to install/update any missing SDKs or tools.]

So basically to solve this issue you have to install the latest Android SDK.

Upvotes: 0

Dilip
Dilip

Reputation: 199

Please Refer the Question

An error occurred while listing Android targets

and the Link developer.android.com/tools/devices/managing-avds-cmdline.html

Most probably the path variable pointing to this android was wrong. I had used %ANDROID_HOME% as variable and scaled the same to path variables %ANDROID_HOME%\SDK\TOOLS. This method doesn't work. Experimentally resolved by directly pointing to the Tools and Platform Tools.

Just based on what I did and it worked for me. Hope You get the Issue resolved.

Upvotes: 1

AlexStack
AlexStack

Reputation: 17441

I had the same issue and solved it by setting the following environment variables:

  • %JAVA_HOME% points to the root of your java installation (not the bin directory). In my computer it is: C:\Program Files\Java\jdk1.8.0. To test that it is configured correctly, open a new terminal and type javac. It should run the java compiler and shouldn't complain that it doesn't know the command. Please note that environment variables are only set when opening a new terminal (at least on windows) so every time you change something you have to open a new terminal.

  • %ANT_HOME% point to the root of where you've installed Apache ant. In my computer it is: C:\Users\User\apache-ant-1.9.3. Test it by running the ant command. It shouldn't complain that the ant command is unknown to your machine. Remember to open a new terminal after setting the path and then try running ant.

  • %ANDROID_HOME% points to where you have installed your android SDK. For example: C:\Users\User\android\sdk. Then try typing emulator to make sure it is installed correctly.

When all of these variables are set, you can use them in the PATH environment variable :

%PATH% contains the following entries: %ANT_HOME%\bin;%ANDROID_HOME%\tools;%ANDROID_HOME%\platform-tools;%JAVA_HOME%\bin

On windows 8 you can configure path and variables by right clicking on the start button, choosing system, and then advanced system settings and clicking on environment variables button. Remember to define the above environment variables above PATH. I defined everything in the user variables and it works just fine.

Upvotes: 16

user3534641
user3534641

Reputation: 307

-Possible solution for those who encounter this error

I had this error and it did relate to the path variables. I thought I had everything set correctly, but I was missing a portion.

First check by typing the command android into command line. If the SDK isn't opened you have not set the variables and/or path correctly.

You should have 3 (or 4 if you have separate android ones) variables.

ANT_HOME, JAVA_HOME and ANDROID_HOME

ANDROID_HOME should point to the sdk. If you (like I did) downloaded the bundle which includes eclipse, you need to have this variable point to the sdk folder inside the android bundle folder, not the android bundle folder itself (eg. C:\Dev\adt-bundle-windows\sdk)

You need to add %ANDROID_HOME%\tools and %ANDROID_HOME%\platform-tools to your path. Along with the link to the ANT bin folder and jdk bin.

I strongly urge you to triple check that all variables are correctly set AND that all four parts are added to the path.

Upvotes: 5

Related Questions