20

I'm trying add the android platform to my cordova project, though I get the error:

$ cordova platform add android -d
cordova library for "android" already exists. No need to download. Continuing.
Checking if platform "android" passes minimum requirements...
Checking Android requirements...
cordova library for "android" already exists. No need to download. Continuing.
Error: An error occurred while listing Android targets
    at /home/jasonshark/.cordova/lib/android/cordova/3.2.0/bin/lib/check_reqs.js:83:29
    at _rejected (/home/jasonshark/.cordova/lib/android/cordova/3.2.0/bin/node_modules/q/q.js:808:24)
    at /home/jasonshark/.cordova/lib/android/cordova/3.2.0/bin/node_modules/q/q.js:834:30
    at Promise.when (/home/jasonshark/.cordova/lib/android/cordova/3.2.0/bin/node_modules/q/q.js:1079:31)
    at Promise.promise.promiseDispatch (/home/jasonshark/.cordova/lib/android/cordova/3.2.0/bin/node_modules/q/q.js:752:41)
    at /home/jasonshark/.cordova/lib/android/cordova/3.2.0/bin/node_modules/q/q.js:574:44
    at flush (/home/jasonshark/.cordova/lib/android/cordova/3.2.0/bin/node_modules/q/q.js:108:17)
    at process._tickCallback (node.js:415:13)

Without the -d it will be:

Checking Android requirements...
[Error: An error occurred while listing Android targets]

I'm not sure what configuration I am missing. In my ~/.bashrc file I have:

### Java
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-i386

export ANDROID_HOME=~/Code/adt-bundle-linux-x86-20131030/sdk/tools
export ANDROID_PLATFORM_TOOLS=~/Code/adt-bundle-linux-x86-20131030/sdk/platform-tools
export PATH=$ANDROID_HOME:$ANDROID_PLATFORM_TOOLS:$PATH 

and I have ant installed:

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

What's missing? Why do i get the error An error occurred while listing Android targets when trying to add the android platform to the cordova project?

Connor Leech
  • 18,052
  • 30
  • 105
  • 150

4 Answers4

18

Cordova has a script to check if all dependencies are present. Is is called when you run cordova platform add android but unfortunatly it's output is not displayed when it fails.

You can try to run it manually, it should be $home/.cordova/lib/android/cordova/3.5.0/bin/check_reqs

The normal output when everything's fine is "Looks like your environment fully supports cordova-android development!", oterwise it should display a clear message about what's missing.

Maybe your issue is that you havent't installed SDK platform for API 19 in android sdk manager (cordova 3.3 or 3.5 uses target sdk 19).

Update: Cordova 3.3 or 3.5 works on SDK 19 only (Android 4.4.2). The error logs does not mention clearly what platform version it is looking for. Typically error messages are:

Unable to add platform android. Please see console for more info.

or

[Error: An error occurred while listing Android targets]

This can also happen when android (sdk/tools) is not in path. I would have loved if the check-script have printed correct error message. BTW, created a PR for them.

ankitjaininfo
  • 11,961
  • 7
  • 52
  • 75
QuickFix
  • 11,661
  • 2
  • 38
  • 50
  • do you know the fix for Windows ? – Francisco Corrales Morales Mar 06 '14 at 15:26
  • 2
    You can run check_reqs by launching `%userprofile%\.cordova\lib\android\cordova\3.3.0\bin\check_reqs` but it's not a fix, just a way to have a clearer message in some cases – QuickFix Mar 06 '14 at 16:07
  • Don't forget to update your cordova version in the command, For eg; PhoneGap 3.4.0 users, it should be `~/.cordova/lib/android/cordova/3.4.0/bin/check_reqs` – Mithun Sreedharan Apr 04 '14 at 10:40
  • 5
    I'm having same problem as OP, with the suggestions provided I get `[Error: An error occurred while listing Android targets]` which is same the error we had in first place. – aesede Apr 11 '14 at 22:54
  • 11
    @aesede I experienced the same issue, which was very frustating. Every step in the Phonegap installation gives an error for something it seems. To fix that error in particular, you need to add the android SDK tools to your PATH variable (/adt-bundle/sdk/tools). I guess this must happen magically for most people, since I had to read the source code to figure out why it wasn't working... – Radley Sustaire Apr 14 '14 at 17:53
  • 3
    @RadGH it doesn't happen magically, it's just explained in the doc : http://cordova.apache.org/docs/en/3.4.0/guide_platforms_android_index.md.html#Android%20Platform%20Guide – QuickFix Apr 14 '14 at 22:25
  • @QuickFix yeah that's clear, the thing is (like in my case) I already had _android sdk tools_ in my PATH correctly set, but finally after a while I've found out that the error was because of the **version** of my android adt-bundle, which was not the last one (or not the version phonegap was looking for). – aesede Apr 14 '14 at 23:20
  • The solution from @aesede worked for me - I added /adt-bundle/sdk/tools to my path and everything started to work. – PRB May 27 '14 at 21:37
2

in .bashrc try adding

export ANT_HOME="/usr/bin/ant"
export PATH="$PATH:$ANT_HOME/bin"
export HOME="/home/username"
export ANDROID_HOME="$HOME/android-bundle/sdk/tools"
export ANDROID_PLATFORM_TOOLS="$HOME/android-bundle/sdk/platform-tools"
export PATH="$ANDROID_HOME:$ANDROID_PLATFORM_TOOLS:$PATH"

or try explicitly define the paths globally.

from the terminal I type:

export PATH=${PATH}:~/dev/adt-bundle-linux-x86_64-20140321/sdk/tools
export PATH=${PATH}:~/dev/adt-bundle-linux-x86_64-20140321/sdk/platform-tools

(rememebr to replace with your own sdk path)

If this doesn't work, try updating the sdk

Orane
  • 2,223
  • 1
  • 20
  • 33
1

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

I had faced the Issue even after the Cordova check_reqs was working correctly without providing any error.But on adding a new platform this error was still being raised. The above method personaly resolved my issue.

Community
  • 1
  • 1
Dilip
  • 199
  • 1
  • 2
  • 15
1

I solved the problem giving full permission for my app folder

$ sudo chmod -R 777 myApp

After that, try again

$ cd myApp
$ ionic platform android
nelson eldoro
  • 2,030
  • 2
  • 14
  • 10