This is just some notes I made, mostly taken from http://docs.phonegap.com/en/3.0.0/guide_overview_index.md.html.
I was installing PhoneGap 3.0.0 on Ubuntu 12.04.
I use Sublime Text 3 for development, so didn’t want any of the Eclipse-based tools.
NB : I’ve revised these notes a bit, to be clearer about what needs to be installed, with 2 options for installing nodejs, and to give a more logical order to the steps..
Environment
First, check you’ve got Java and Ant installed – you’ll need those later:
sudo apt-get install default-jre
sudo apt-get install default-jdk
sudo apt-get install ant
Next, install node from source:
git clone https://github.com/joyent/node.git
cd node
git checkout v0.10.26 #Try checking nodejs.org for what the stable version is
./configure && make && sudo make install
Alternatively, upgrade npm, and get the latest nodejs (by installing ‘n’ and running that):
sudo npm update npm -g
sudo npm install n -g
sudo n stable
Now install phonegap itself using npm:
sudo npm install -g phonegap
Download the Android sdk from http://developer.android.com/sdk/index.html, and unpack it somewhere (I had problems with file permissions when I put it under /opt, so I ended up putting it under my home directory, as ~/android):
mv ~/Downloads/adt-bundle-linux-x86-20130917.zip ~/android
cd ~/android
unzip adt-bundle-linux-x86-20130917.zip
Update PATH in ~/.bashrc to include the phonegap tools:
# Add android sdk
PATH=$PATH:~/android/adt-bundle-linux-x86-20130917/sdk/platform-tools:~/android/adt-bundle-linux-x86-20130917/sdk/tools
and then ‘source ~/.bashrc’ to make sure you’ve got the new path setup.
Create an app
Create a phonegap app (I use a “projects” subdirectoy):
cd ~/projects
phonegap create my-app
cd my-app
Run the app
Before you run the app, you’ll need to set up an emulator – run the android tool:
android
You may need to select a target (e.g. “Android 4.2.2 (API 17)”), and click the “Install 8 packages..” button (may need several clicks to accept all the licences)
Now setup and start an emulator – in the ‘android’ util, go to Tools -> Manage AVDs, go to the “Device Definitions”, select a device, and use the “Create AVD” button to create a new AVD. Then use the “Start..” button to start the AVD (it may take a surprisingly long time to start fully).
Run the app:
phonegap local run android
You should see the app compile and install on the emulator.
You can do the compile and install steps separately:
phonegap local build android
phonegap install android
Deploying to a real phone
The emulator seems to run very slowly, and not give much sense of what the app will actually be like on the phone.
So, deploy the app – plug in Android phone via USB, select “USB debugging” in the Developer section of the settings on the phone, and the app will be installed on the phone when you next do “phonegap install…”
Add some plugins to the project
Once you get going, add some plugins to the project:
phonegap local plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-device.git
phonegap local plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-media.git
it works like a charm.
i have to install ant after a step with:
sudo apt-get -u install ant
everything else happen as you mention.
regards
Thank you for the great instructions! Very clean. I would add one thing. I had to install Apache ant. So I also had to do:
sudo aptitude install ant
Many thanks Manuel and Michael for pointing out that Ant needs to be installed too.
Dears ,
when i write this command :sudo npm install n -g
it give me this error , so please advice
npm http GET https://registry.npmjs.org/n
npm ERR! Error: failed to fetch from registry: n
npm ERR! at /usr/share/npm/lib/utils/npm-registry-client/get.js:139:12
npm ERR! at cb (/usr/share/npm/lib/utils/npm-registry-client/request.js:31:9)
npm ERR! at Request._callback (/usr/share/npm/lib/utils/npm-registry-client/request.js:136:18)
npm ERR! at Request.callback (/usr/lib/nodejs/request/main.js:119:22)
npm ERR! at Request. (/usr/lib/nodejs/request/main.js:212:58)
npm ERR! at Request.emit (events.js:88:20)
npm ERR! at ClientRequest. (/usr/lib/nodejs/request/main.js:412:12)
npm ERR! at ClientRequest.emit (events.js:67:17)
npm ERR! at HTTPParser.onIncoming (http.js:1261:11)
npm ERR! at HTTPParser.onHeadersComplete (http.js:102:31)
npm ERR! You may report this log at:
npm ERR!
npm ERR! or use
npm ERR! reportbug –attach /home/hamdy/npm-debug.log npm
npm ERR!
npm ERR! System Linux 3.2.0-59-generic
npm ERR! command “node” “/usr/bin/npm” “install” “n” “-g”
npm ERR! cwd /home/hamdy
npm ERR! node -v v0.6.12
npm ERR! npm -v 1.1.4
npm ERR! message failed to fetch from registry: n
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /home/hamdy/npm-debug.log
npm http GET https://registry.npmjs.org/n
npm ERR! Error: failed to fetch from registry: n
npm ERR! at /usr/share/npm/lib/utils/npm-registry-client/get.js:139:12
npm ERR! at cb (/usr/share/npm/lib/utils/npm-registry-client/request.js:31:9)
npm ERR! at Request._callback (/usr/share/npm/lib/utils/npm-registry-client/request.js:136:18)
npm ERR! at Request.callback (/usr/lib/nodejs/request/main.js:119:22)
npm ERR! at Request. (/usr/lib/nodejs/request/main.js:212:58)
npm ERR! at Request.emit (events.js:88:20)
npm ERR! at ClientRequest. (/usr/lib/nodejs/request/main.js:412:12)
npm ERR! at ClientRequest.emit (events.js:67:17)
npm ERR! at HTTPParser.onIncoming (http.js:1261:11)
npm ERR! at HTTPParser.onHeadersComplete (http.js:102:31)
npm ERR! You may report this log at:
npm ERR!
npm ERR! or use
npm ERR! reportbug –attach /home/devid/npm-debug.log npm
npm ERR!
npm ERR! System Linux 3.8.0-35-generic
npm ERR! command “node” “/usr/bin/npm” “install” “n” “-g”
npm ERR! cwd /home/devid
npm ERR! node -v v0.6.12
npm ERR! npm -v 1.1.4
npm ERR! message failed to fetch from registry: n
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /home/devid/npm-debug.log
npm not ok
Please share resolution.
I had resolved error:
npm ERR! Error: failed to fetch from registry: n
Fire below command then try all about command works fine.
npm config set registry http://registry.npmjs.org/
@tejas
When I had use below command:
phonegap local run android
It throws error:
===========================================
/home/tejastank/.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/devid/.cordova/lib/android/cordova/3.3.0/bin/lib/check_reqs.js:87:29
at _rejected (/home/devid/.cordova/lib/android/cordova/3.3.0/bin/node_modules/q/q.js:808:24)
at /home/devid/.cordova/lib/android/cordova/3.3.0/bin/node_modules/q/q.js:834:30
at Promise.when (/home/devid/.cordova/lib/android/cordova/3.3.0/bin/node_modules/q/q.js:1079:31)
at Promise.promise.promiseDispatch (/home/devid/.cordova/lib/android/cordova/3.3.0/bin/node_modules/q/q.js:752:41)
at /home/devid/.cordova/lib/android/cordova/3.3.0/bin/node_modules/q/q.js:574:44
at flush (/home/devid/.cordova/lib/android/cordova/3.3.0/bin/node_modules/q/q.js:108:17)
at process._tickCallback (node.js:415:13)
Unable to get running emulator .
What steps to carry for this ?
@Tejas Tank
same here
worked great. after searching hours on the internet, found your article and it all worked for me. thanks a ton.
I’m so confused and worried with phonegap errors. Although i’m a veteran Java and Python programmer i has never been launched phonegap.
And this is last error after your recipe:
[error] /home/suat/.cordova/lib/android/cordova/3.4.0/bin/create: Command failed with exit code 8
Thanks
Hallo!!!
When im trying to run the app in my device i got the error:
eduardo@eduardo-Inspiron-N5110:~/my-app$ phonegap run adnroid –device=HT24PW302124
/usr/lib/node_modules/phonegap/lib/phonegap/run.js:72
self.phonegap.emit(‘log’, ‘detecting’, platform.human, ‘SDK environment…
^
TypeError: Cannot read property ‘human’ of undefined
at RunCommand.execute (/usr/lib/node_modules/phonegap/lib/phonegap/run.js:72:52)
at RunCommand.run (/usr/lib/node_modules/phonegap/lib/phonegap/run.js:55:10)
at PhoneGap.run (/usr/lib/node_modules/phonegap/lib/phonegap/util/command.js:28:25)
at CLI.module.exports [as run] (/usr/lib/node_modules/phonegap/lib/cli/run.js:38:14)
at CLI.module.exports [as argv] (/usr/lib/node_modules/phonegap/lib/cli/argv.js:66:17)
at Object. (/usr/lib/node_modules/phonegap/bin/phonegap.js:26:21)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
eduardo@eduardo-Inspiron-N5110:~/my-app$
any idea?
I’ve got an error message when I try to run:
sudo npm install -g n
npm http GET https://registry.npmjs.org/n
npm ERR! Error: failed to fetch from registry: n
npm ERR! at /usr/share/npm/lib/utils/npm-registry-client/get.js:139:12
npm ERR! at cb (/usr/share/npm/lib/utils/npm-registry-client/request.js:31:9)
npm ERR! at Request._callback (/usr/share/npm/lib/utils/npm-registry-client/request.js:136:18)
npm ERR! at Request.callback (/usr/lib/nodejs/request/main.js:119:22)
npm ERR! at Request. (/usr/lib/nodejs/request/main.js:212:58)
npm ERR! at Request.emit (events.js:88:20)
npm ERR! at ClientRequest. (/usr/lib/nodejs/request/main.js:412:12)
npm ERR! at ClientRequest.emit (events.js:67:17)
npm ERR! at HTTPParser.onIncoming (http.js:1261:11)
npm ERR! at HTTPParser.onHeadersComplete (http.js:102:31)
npm ERR! You may report this log at:
npm ERR!
npm ERR! or use
npm ERR! reportbug –attach /usr/local/google/home/pavelm/npm-debug.log npm
npm ERR!
npm ERR! System Linux 3.2.5-gg1336
npm ERR! command “node” “/usr/bin/npm” “install” “-g” “n”
npm ERR! cwd /usr/local/google/home/pavelm
npm ERR! node -v v0.6.12
npm ERR! npm -v 1.1.4
npm ERR! message failed to fetch from registry: n
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /usr/local/google/home/pavelm/npm-debug.log
npm not ok
Just resolved the error above:
sudo npm config set registry http://registry.npmjs.org/
Thanks to @tejas.
When I run ‘ sudo n stable’ in ubuntu 14.04 64-bit, I get this error message:
~$ sudo n stable
install : v0.10.26
/usr/local/bin/n: regel 216: curl: opdracht niet gevonden (English = command not found)
Error: invalid version 0.10.26
What goes wrong? and what needs to be changed?
Thank you in advance,
Carolien
Pingback: ?ubuntu???PhoneGap android?????? | ????
I’ve updated the notes above..
* you need java and ant installed
* there seemed to be problems with getting node installed, so I’ve suggested compiling it from source
* putting the Android SDK under your own home directory avoids a lot of file permission problems
* I’ve updated the instructions for setting up the emulator
Hope it’s a bit easier to follow.
Pingback: How to Install PhoneGap in Ubuntu | codezone4
Thank you very much. It was very helpful 😀
Supa! Thanks a lot!
Great and nice blog. It’s also very interesting. We also have a website about Engineerbabu.
Please visit our website: http://engineerbabu.com/
Thank you! Great guide.
Pingback: Correct Steps to Setting Up Cordova in Linux Mint « Code Dominion
Great article Sir!
For the first time I was trying to install phonegab by your instructions went simething wrong, but now everythink works.
You saved my week 😉
Thank You so much!
Very helpful and clean set of instructions which actually solves a quite complicated process due to the use of application dependencies plus versioning conflicts. I only had one problem with a node directory error. I did also find a solution which is quite simpel:
you just need to add a symbolic link with this command:
ln -s /usr/bin/nodejs /usr/bin/node (NB both directories are defualt).
After that Phonegap works like a charm and all commands works and thereby results in a complete development environment setup for crossplatform development.
Thank you very much for these instructions. I greatly respect the the fine job you have done here.
Best regards
Klaes
Hello!
This is my errors to phonegap run android in my-app:
http://paste.ubuntu.com/7707557/
Really nice article . i also tried to cover this topic in my blog . May be someone will find it useful http://javacourseblog.blogspot.in/2013/05/How-to-Use-PhoneGap-on-Linux-Ubuntu-or-Android-Application-Development.html
Pingback: Setting up PhoneGap on Ubuntu for Android app development | Julian Higman : Blog - appgong
Thanks! It works perfectly! 🙂
Thank you very much for this, the first Linux cordova/phonegap guide I’ve used that worked as expected without any hiccups!
Fresh install of Elementary OS, fresh install of Ionic/Cordova and Webstorm IDE, I’m ready to go! 🙂
I really thank you! 🙂
On Ubuntu 14.04 64-bit I had to add:
sudo apt-get install lib32z1 lib32stdc++6
AND to hurry up the emulator use kvm as mentioned here:
http://developer.android.com/tools/devices/emulator.html#accel-vm
Emulator is up and ready in a few seconds 🙂
I have this error…!!!!
jrortiz85@jrortiz85-HP-Pro-3130-Microtower-PC:~/projectosGap/hello$ phonegap run android
[phonegap] detecting Android SDK environment…
[phonegap] using the local environment
[phonegap] adding the Android platform…
/home/jrortiz85/.cordova/lib/android/cordova/3.5.1/bin/node_modules/q/q.js:126
throw e;
^
Error: An error occurred while listing Android targets
at /home/jrortiz85/.cordova/lib/android/cordova/3.5.1/bin/lib/check_reqs.js:87:29
at _rejected (/home/jrortiz85/.cordova/lib/android/cordova/3.5.1/bin/node_modules/q/q.js:808:24)
at /home/jrortiz85/.cordova/lib/android/cordova/3.5.1/bin/node_modules/q/q.js:834:30
at Promise.when (/home/jrortiz85/.cordova/lib/android/cordova/3.5.1/bin/node_modules/q/q.js:1079:31)
at Promise.promise.promiseDispatch (/home/jrortiz85/.cordova/lib/android/cordova/3.5.1/bin/node_modules/q/q.js:752:41)
at /home/jrortiz85/.cordova/lib/android/cordova/3.5.1/bin/node_modules/q/q.js:574:44
at flush (/home/jrortiz85/.cordova/lib/android/cordova/3.5.1/bin/node_modules/q/q.js:108:17)
at process._tickCallback (node.js:419:13)
{ [Error: /home/jrortiz85/.cordova/lib/android/cordova/3.5.1/bin/create: Command failed with exit code 8] code: 8 }
[error] /home/jrortiz85/.cordova/lib/android/cordova/3.5.1/bin/create: Command failed with exit code 8
I followed the instructions , the installation completed with the following
https://github.com/component/global/archive/v2.0.1.tar.gz
/usr/local/bin/phonegap -> /usr/local/lib/node_modules/phonegap/bin/phonegap.js
phonegap@3.6.0-0.21.19 /usr/local/lib/node_modules/phonegap
??? pluralize@0.0.4
??? colors@0.6.0-1
??? semver@1.1.0
??? minimist@0.1.0
??? qrcode-terminal@0.9.4
??? shelljs@0.1.4
??? prompt@0.2.11 (revalidator@0.1.8, pkginfo@0.3.0, read@1.0.5, winston@0.6.2, utile@0.2.1)
??? phonegap-build@0.8.4 (qrcode-terminal@0.8.0, shelljs@0.0.9, optimist@0.3.7, phonegap-build-api@0.3.3)
??? cordova-lib@0.21.13 (osenv@0.0.3, properties-parser@0.2.3, bplist-parser@0.0.6, mime@1.2.11, q@0.9.7, semver@2.0.11, unorm@1.3.3, underscore@1.4.4, npm@1.3.4, dep-graph@1.1.0, elementtree@0.1.5, xcode@0.6.7, rc@0.3.0, npmconf@0.1.16, glob@3.2.11, tar@0.1.20, plist@1.0.1, request@2.22.0, cordova-js@3.6.4)
??? connect-phonegap@0.13.0 (home-dir@0.1.2, connect-inject@0.3.2, ip@0.3.1, mkpath@0.1.0, ncp@0.6.0, findit@2.0.0, shelljs@0.2.6, request-progress@0.3.1, useragent@2.0.8, tar@0.1.19, node-static@0.7.0, localtunnel@1.3.0, gaze@0.4.3, request@2.33.0, archiver@0.10.1, connect@2.12.0, socket.io@1.0.6)
after running the command phonegap, nothing happens, no errors or messages, even runing
phonegap create my-app
does not create the application or give any errors
Any idea where i might have missed it
Pingback: Android Sdk On Ubuntu 14.04 - Cars And Autos Blog
Thanks a lot for this article, I’m unable to execute this:
cordova platform add android
Please help, it was working fine before
With sudo i got
adepoju@attemptexams:~/hello$ sudo cordova platform add android
Creating android project…
/home/adepoju/.cordova/lib/npm_cache/cordova-android/3.6.4/package/bin/node_modules/q/q.js:126 throw e; ^ Error: ANDROID_HOME is not set and “android” command not in your PATH. You must fulfill at least one of these conditions. at /home/adepoju/.cordova/lib/npm_cache/cordova-android/3.6.4/package/bin/lib/check_reqs.js:159:19 at _fulfilled (/home/adepoju/.cordova/lib/npm_cache/cordova-android/3.6.4/package/bin/node_modules/q/q.js:798:54) at self.promiseDispatch.done (/home/adepoju/.cordova/lib/npm_cache/cordova-android/3.6.4/package/bin/node_modules/q/q.js:827:30) at Promise.promise.promiseDispatch (/home/adepoju/.cordova/lib/npm_cache/cordova-android/3.6.4/package/bin/node_modules/q/q.js:760:13) at /home/adepoju/.cordova/lib/npm_cache/cordova-android/3.6.4/package/bin/node_modules/q/q.js:821:14 at flush (/home/adepoju/.cordova/lib/npm_cache/cordova-android/3.6.4/package/bin/node_modules/q/q.js:108:17) at process._tickCallback (node.js:419:13) at Function.Module.runMain (module.js:499:11) at startup (node.js:119:16) at node.js:906:3 Error: /home/adepoju/.cordova/lib/npm_cache/cordova-android/3.6.4/package/bin/create: Command failed with exit code 8 at ChildProcess.whenDone (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/cordova/superspawn.js:135:23) at ChildProcess.emit (events.js:98:17) at maybeClose (child_process.js:755:16) at Process.ChildProcess._handle.onexit (child_process.js:822:5)
This is the great work and everyone take benefit because it work fine .
If someone wants web application and ios app then this will help you.
http://julianhigman.com/blog/2013/10/17/notes-on-setting-up-phonegap-on-ubuntu-for-android-app-development/