0

I am new to Cordova and phonegap but have Android working on my ubuntu 12.04. I followed this official guide and manage to install cordova.

Despite my machine supports android sdk, when I run this command:

cordova platform add android

I get the following exception:

 *cordova platform add android

 Creating android project...
 /root/.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 /root/.cordova/lib/android/cordova/3.4.0/bin/lib/check_reqs.js:87:29
at _rejected (/root/.cordova/lib/android/cordova/3.4.0/bin/node_modules/q/q.js:808:24)
at /root/.cordova/lib/android/cordova/3.4.0/bin/node_modules/q/q.js:834:30
at Promise.when    (/root/.cordova/lib/android/cordova/3.4.0/bin/node_modules/q/q.js:1079:31)
at Promise.promise.promiseDispatch (/root/.cordova/lib/android/cordova/3.4.0/bin/node_modules/q/q.js:752:41)
at /root/.cordova/lib/android/cordova/3.4.0/bin/node_modules/q/q.js:574:44
at flush (/root/.cordova/lib/android/cordova/3.4.0/bin/node_modules/q/q.js:108:17)
at process._tickCallback (node.js:415:13)
Error: /root/.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)
root@sergio-Aspire-5755G:/home/sergio/Development/HelloWorld#  cordova platforms ls
Installed platforms: 
Available platforms: android, blackberry10, firefoxos, ubuntu
root@xxx-Aspire-5755G:/home/sergio/Development/HelloWorld# cordova platform add android
Creating android project...
/root/.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 /root/.cordova/lib/android/cordova/3.4.0/bin/lib/check_reqs.js:87:29
at _rejected (/root/.cordova/lib/android/cordova/3.4.0/bin/node_modules/q/q.js:808:24)
at /root/.cordova/lib/android/cordova/3.4.0/bin/node_modules/q/q.js:834:30
at Promise.when    (/root/.cordova/lib/android/cordova/3.4.0/bin/node_modules/q/q.js:1079:31)
at Promise.promise.promiseDispatch (/root/.cordova/lib/android/cordova/3.4.0/bin/node_modules/q/q.js:752:41)
at /root/.cordova/lib/android/cordova/3.4.0/bin/node_modules/q/q.js:574:44
at flush (/root/.cordova/lib/android/cordova/3.4.0/bin/node_modules/q/q.js:108:17)
at process._tickCallback (node.js:415:13)
Error: /root/.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)*

I tried and see other post like this but noone helped me.

Android sdk version 19 is installed

Community
  • 1
  • 1
eeadev
  • 3,662
  • 8
  • 47
  • 100
  • You're folling doc for phonegap 2.9 and using cordova 3.4... things have changed a lot between 2.9 and 3.X – QuickFix Mar 26 '14 at 15:34
  • 1
    Try to run `$home/.cordova/lib/android/cordova/3.4.0/bin/check_reqs` to see if it displays a clearer message about the error. – QuickFix Mar 26 '14 at 15:36
  • this is what I get:~/.cordova/lib/android/cordova/3.4.0/bin# ./check_reqs [Error: An error occurred while listing Android targets] – eeadev Mar 26 '14 at 15:44
  • if you run the `android` command does it start the sdk manager? If yes ensure you installed the sdk 19. – QuickFix Mar 26 '14 at 15:50
  • yes it starts the sdkmanager and the v 19 is installed, I ll update my question – eeadev Mar 26 '14 at 15:55
  • 1
    I haven't cordova 3.4 so I'll not be able to help you more. What you can do is open check_reqs.js at line 87 and see what command it's trying to launch. I can't find it but I remember I helped someone with a similar issue and the cause had something to do with the path of the project or the project name. – QuickFix Mar 26 '14 at 16:20
  • I solved adding it to my .bashrc: export PATH=$PATH:/opt/adt-bundle-linux-x86_64-20131030/sdk/platform-tools:/opt/adt-bundle-linux-x86_64-20131030/sdk/tools. This post can be closed – eeadev Mar 26 '14 at 18:01
  • possible duplicate of [An error occurred while listing Android targets](http://stackoverflow.com/questions/23466479/an-error-occurred-while-listing-android-targets) – Dilip Sep 29 '14 at 09:27

3 Answers3

1

1) run "android avd" command and create at least one virtual device based on a version of a previously downloaded SDK.

2) sudo apt-get install ant1.8

worked for me.
kamlesh
  • 238
  • 1
  • 5
1

You need to check if path to Android SDK is correct or not.
Check your Environment Variables PATH, ANDROID_PLATFORM_TOOLS, ANDROID_HOME, ANT_HOME you can check if they are configured correctly by echo %ANDROID_HOME% check for all Paths you will know which path is not configured properly.

Deep Mehta
  • 1,250
  • 1
  • 16
  • 29
0

I solved this way:

adding the below line to my .bashrc:

export PATH=$PATH:/opt/adt-bundle-linux-x86_64-20131030/sdk/platform-tools:/opt/adt-bun‌​dle-linux-x86_64-20131030/sdk/tools

eeadev
  • 3,662
  • 8
  • 47
  • 100