Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)
  • Project is created using cordova create fapp com.fapp Fapp
  • System is windows 8
  • ANT, JAVA (JDK 1.7.0_51 and JRE7), Android SDKs are installed from (17-19.0.3) and Android APIs (17-19)
  • All environment variables for JAVA, ANDROID and ANT are set as well as path to bin for all of them into Path variable.

I really tried everything but keeps throwing this problem.

EDIT:

  • Answer here did not help: cordova ubuntu: An error occurred while listing Android targets
  • Permissions are set to Everyone full control and same issue

FINAL SOLUTION

  • Finally I re-installed JDK and Android SDK and now everything works even it is still mystery to me.
like image 456
Andrej Kaurin Avatar asked Mar 08 '14 21:03

Andrej Kaurin


1 Answers

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.

like image 121
AlexStack Avatar answered Nov 15 '22 05:11

AlexStack