PhoneGap/Cordova Android Development

Androidnode.jsUbuntuCordova

Android Problem Overview


UPDATE 1:

This was everything I did in the end:

sudo aptitude install -y python-software-properties python g++ make
sudo add-apt-repository -y ppa:chris-lea/node.js
sudo aptitude update
sudo aptitude install nodejs
sudo aptitude install npm
sudo npm install -g cordova
sudo npm install -g phonegap
phonegap create my-app
cd my-app
export PATH=${PATH}:/home/oshirowanen/Downloads/adt-bundle-linux-x86_64-20131030/sdk/platform-tools:/home/oshirowanen/Downloads/adt-bundle-linux-x86_64-20131030/sdk/tools
sudo aptitude install ant
cordova platform add android
android create avd --name my_and --target 1
phonegap run android

Was any of that not neccessary?


ORIGINAL QUESTION:

On my Ubuntu 12.04 computer, I've just installed node.js with npm and cordova:

$ node -v
v0.10.23

$ npm -v
1.3.17

$ cordova -v
3.3.0-0.1.1

When I try to add android:

$ cordova platform add android

I get the following output:

Creating android project...

/usr/lib/node_modules/cordova/node_modules/q/q.js:126
                    throw e;
                          ^
Error: An error occured during creation of android sub-project. 

/home/oshirowanen/.cordova/lib/android/cordova/3.3.0/bin/node_modules/q/q.js:126
                    throw e;
                          ^
Error: An error occurred while listing Android targets
    at /home/oshirowanen/.cordova/lib/android/cordova/3.3.0/bin/lib/check_reqs.js:87:29
    at _rejected (/home/oshirowanen/.cordova/lib/android/cordova/3.3.0/bin/node_modules/q/q.js:808:24)
    at /home/oshirowanen/.cordova/lib/android/cordova/3.3.0/bin/node_modules/q/q.js:834:30
    at Promise.when (/home/oshirowanen/.cordova/lib/android/cordova/3.3.0/bin/node_modules/q/q.js:1079:31)
    at Promise.promise.promiseDispatch (/home/oshirowanen/.cordova/lib/android/cordova/3.3.0/bin/node_modules/q/q.js:752:41)
    at /home/oshirowanen/.cordova/lib/android/cordova/3.3.0/bin/node_modules/q/q.js:574:44
    at flush (/home/oshirowanen/.cordova/lib/android/cordova/3.3.0/bin/node_modules/q/q.js:108:17)
    at process._tickCallback (node.js:415:13)

    at /usr/lib/node_modules/cordova/src/platform.js:244:30
    at ChildProcess.exithandler (child_process.js:641:7)
    at ChildProcess.EventEmitter.emit (events.js:98:17)
    at maybeClose (child_process.js:735:16)
    at Socket.<anonymous> (child_process.js:948:11)
    at Socket.EventEmitter.emit (events.js:95:17)
    at Pipe.close (net.js:466:12)

Anyone know why this is happening and how to resolve it?

I get the same issue with PhoneGap.

Android Solutions


Solution 1 - Android

It's possible that the Android tools binaries are not in your path.

According to the PhoneGap docs (http://docs.phonegap.com/en/2.9.0/guide_getting-started_android_index.md.html), you need to include the Android SDK's tools and platform-tools in your PATH environment variable.

> export PATH=${PATH}:/Development/adt-bundle/sdk/platform-tools:/Development/adt-bundle/sdk/tools

where Development is the path you installed your SDK.

Solution 2 - Android

Run the "android" command from your adt\sdk\tools folder and install the latest Tools and SDK. Also make sure your PATH has the right variables.

For this you will need ANT to be installed , a JAVA JDK and an Android SDK installed

JAVA_HOME (C:\Program Files\Java\jdk)

ANT_HOME ({ant location}\apache\apache-ant)

ANDROID_HOME ({android sdk location}\android-sdk)

Add these to your PATH variable like %ANT_HOME%/bin;%ANDROID_HOME%\tools;%ANDROID_HOME%\platform-tools;%JAVA_HOME%\bin

Close and re-open your cmd and run your command again.

Solution 3 - Android

I'm running Ubuntu 12.04 and was having the same problem as you until a few minutes ago.

The two things I've noted that I had missed during installation:

  1. The Android version should be 19 and you should be able to type 'android' at the console and see some output or see a window pop-up. Make sure that you add the path to the folder where android.jar is located to your PATH variable, and set ANDROID_HOME to that same path as well. Typically, you would do this in your .bashrc file or in /etc/environment If you edit either of these files, you'll need to either 'source ~/.bashrc' or reopen your terminal to force it to reload the file. Type 'android' to make sure its working.

  2. I observed that the cordova setup script was attempting to write files into a subdirectory 'add-ons' of the Android SDK. That directory does not exist in the Android 19 distribution itself. Consequently, I created it manually and made it writeable by my user account.

ex: Android distribution path:

/opt/android/

The path that its trying to write to:

/opt/android/sdk/add-ons

Once I had done that I was able to get past the problem you've noted above.

Solution 4 - Android

It looks like the cordova andorid library file corrupted in your home directory.

Try to remove home//.cordova directory and do this again cordova platform add android in your cordova project.

Make sure you have sourced /platform-tools and /tools to PATH.

Solution 5 - Android

Android

The Android command-line tools are built upon shell scripts. You must have the Android SDK's tools and platform-tools folders in your PATH!

Create a project

Run the create command with the following parameters:

Path to your new Cordova Android project

Package name, following reverse-domain style convention

Main Activity name

$ /path/to/cordova-android/bin/create /path/to/my_new_cordova_project com.example.cordova_project_name CordovaProjectName

Solution 6 - Android

It looks like this error could also be caused by the absence of a compatible Android SDK version (at the moment 4.2).

Solution 7 - Android

I use cordova. 2days I have same problem"java,ant,android,cordova,command test is ok, but run cordova platform add android show me Error: An error occurred while listing Android targets". Now I fixit use: "chmod 777 ant and android sdk place" ,then it will work. I use ubuntu 14.04 32bit,

Solution 8 - Android

if the problem still exist please make sure that you have the right permissions try

sudo chmo-R 777 /home/your-user-name/.cordova/

Also make sure that you are NOT using sudo to add Android as a platform

This is incorrect in the default Cordova installation

sudo cordova platform add android

Just do

cordova platform add android

Solution 9 - Android

I've searched a lot for this, and what worked for me was setting the shell variable $ANDROID_HOME to the path of the sdk/ folder in my adt-bundle directory from android. Use export to do this:

export ANDROID_HOME="/Users/YOUR_USER/Developer/adt-bundle/sdk/" but be sure to change the directory to match yours.

Good Luck!

Solution 10 - Android

Not sure if someone else had a problem with this, but when removed and added my platform again, I realized in my config.xml I had <icon src='...'> and the path inside the src was wrong.

Here was the error output I received when I added the platform again:cp: no such file or directory: C:\Users\{pathtofile}.png.

After I fixed the path, it worked fine.

Solution 11 - Android

It can be that your cordova installation have been corrupted try to remove your .cordova folder "rm -R ~/.cordova" And "run cordova platform add android" again

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionoshirowanenView Question on Stackoverflow
Solution 1 - AndroidTomLView Answer on Stackoverflow
Solution 2 - AndroidLlewellyn CollinsView Answer on Stackoverflow
Solution 3 - AndroidevolvingfasterView Answer on Stackoverflow
Solution 4 - AndroidNagendhiranView Answer on Stackoverflow
Solution 5 - Androiduser1374View Answer on Stackoverflow
Solution 6 - AndroidrcasonView Answer on Stackoverflow
Solution 7 - AndroidDr.MaskView Answer on Stackoverflow
Solution 8 - AndroidKhaled AwadView Answer on Stackoverflow
Solution 9 - Androiduser3689258View Answer on Stackoverflow
Solution 10 - AndroidsuperjisanView Answer on Stackoverflow
Solution 11 - AndroidErik AxelssonView Answer on Stackoverflow