PhoneGap/Cordova Android Development

Posted on Jan 17, 2023

Question

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.

Answer

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.