Hybrid mobile application development is a hot topic these days. PhoneGap is one of the frameworks that can be used to develop hybrid mobile apps. If you are new to hybrid mobile application development read this post. You only have to follow these steps to have a PhoneGap app up and running in your Ubuntu. Before that,
What’s PhoneGap
PhoneGap is a free and open source framework that allows you to create mobile apps using standardized web APIs for the platforms you care about.
See the image below for the build process of PhoneGap.
Note that You need to have Java on your Ubuntu. Let’s start.
1. Install nodejs
sudo apt-get update sudo apt-get install nodejs
Let’s install npm, which is the Node.js package manager. You can do this by typing
sudo apt-get install npm
The NodeJS is installed & named as nodejs. But PhoneGap, expect the executable to be named node. To fix this inconsistency, create a symlink named node that points to nodejs as follows.
sudo ln -s /usr/bin/nodejs /usr/bin/node
2. Install Git
sudo apt-get install git
3. Install Ant
sudo apt-get install ant
4. Install PhoneGap
sudo npm install -g phonegap
let’s install libraries that PhoneGap is dependent on.
sudo apt-get install lib32z1 lib32ncurses5 lib32bz2-1.0 lib32stdc++6
type phonegap on the command line and check whether PhoneGap has installed correctly as shown below.
5. Get the Android SDK
You can download the SDK here. Extract the package to /usr/local/android-sdk using below command. Any other preferred place would be fine but make sure to change the path accordingly.
sudo tar -zxvf ~/Downloads/android-sdk_r24.0.2-linux.tgz -C /usr/local/
If you have any issue refer this thread. Complete Installation Guide for Android SDK / ADT Bundle on Ubuntu.
Now let’s set the environment variables in the bash configuration file, so that PhoneGap can call the Android emulator. Edit the .bashrc file as below.
vim ~/.bashrc
Add the below lines.
export PATH=$PATH:/usr/local/android-sdk-linux/ export PATH=$PATH:/usr/local/android-sdk-linux/tools export PATH=$PATH:/usr/local/android-sdk-linux/platform-tools export PATH=$PATH:/usr/local/android-sdk-linux/build-tools
Update the newly added alias in the existing terminal.
source ~/.bashrc
Type android and see whether Android SDK Manager is started as shown below.
6. Let’s install a faster emulator
You can use the android emulator if you really prefer it but rather than using the slow android emulator today I’ll show an emulator which is faster and better. Genymotion. You may have to create an account download the appilcation. Also note that account will be used at later when you run the application as well.
Let’s download from this link. Set the permission before you start running the application as shown below.
chmod u+x genymotion-2.1.0_x64.bin ./genymotion-2.1.0_x64.bin
You might see the below error if VirtualBox is not installed in your system which is required by Genymotion.
Below command will fix the issue.
sudo apt-get install virtualbox
Now let’s run Genymotion.
cd /home/dasunhegoda/Downloads/genymotion/ ./genymotion
Now login to the genymotion account and create an emulator. Refer this link for more info on setting up Genymotion.
7. Let’s create a phonegap appilcation
Create a PhoneGap project using below command.
phonegap create testapp
Add Android as a platform to be built.
phonegap platform add android
To list the available platform try the below command(Optional).
phonegap platform -ls
Now let run the application. Make sure you have started your emulator so that application will be started in it.
phonegap run android
Tips & Tricks
Phonegap is built on Apache Cordova. Apache Cordova is the engine that powers PhoneGap. Therefore you can replace some of the Phonegap command with Cordova. If you really want to know the exact difference read this post. Is there a difference between PhoneGap and Cordova commands? Answer is here. Instead of typing
phonegap run android
type
cordova run android
which will work fine as well. But when you type Cordova commands you will see a more detailed output then PhoneGap commands which is helpful for debugging purposes. See the Apache Cordova installation guide here. Also refer the PhoneGap Wiki as well.
If you have any questions let me know in the comments below. Your feedback is highly appreciated(happy-face).
Hi,
Installed phonegap using,,
sudo npm install -g phonegap
but …..
sudo apt-get install lib32z1 lib32ncurses5 lib32bz2-1.0 lib32stdc++6
…is not working…. error is given below
E: Unable to locate package lib32z1
E: Unable to locate package lib32ncurses5
E: Unable to locate package lib32bz2-1.0
E: Couldn’t find any package by regex ‘lib32bz2-1.0’
E: Unable to locate package lib32stdc++6
E: Couldn’t find any package by regex ‘lib32stdc++6
typed phonegap on the terminal but showing nothing…
help me
Thank you in advance
Execute the below command 1st then try the command.
Hello,
The following command does not work. The package is not located too.
sudo apt-get install lib32z1:i386
Hey Julien, im having the same issue, did you manage to find solution?
Hi kloshar4o, I aborted this installation. I’ve better results with the Kivy Framework.
Thanks for this article.
Didn’t know about genymotion and it’s really great :)
I’m glad I could help
Hi,
Can u please tell me how to install phonegap on centos
Refer this blog-post.
http://mohiplanet.blogspot.com/2014/06/getting-started-with-phonegapcordova.html
Do I need to install JDK?
Yes, You need to have Java on your Ubuntu
Hi, This is a great article. I followed your instructions. I could not install the libraries mentioned in the article. Errors were unable to locate the packages. And also the commands listed after typing phonegap from the command line, doesn’t list all the commands that you have. I have only these
Commands:
create create a phonegap project
build build a specific platform
install install a specific platform
run build and install a specific platform
local [command] development on local system
remote [command] development in cloud with phonegap/build
help [command] output usage information
version output version number
Options:
-v, –version output version number
-h, –help output usage information
Platforms:
android target Android
blackberry target BlackBerry 10
ios target iOS
wp7 target Windows Phone 7
wp8 target Windows Phone 8
Examples:
$ phonegap help create
$ phonegap help remote build
$ phonegap create path/to/my-app
$ phonegap remote build android
Can you please help solving? phonegap -v shows 0.9.4
Thanks much in advance.
These are commands that come with PhoneGap. But underneath it uses Cordova.Therefore you should be able to access them but makes sure all the libs are installed.
Thanks.. But I couldn’t able to install the libs that u have mentioned. I get unable to locate package
Hi, This is a great article. I followed your instructions, but i have not progressing at point 5, exactly on editing ./bashrc,
when i type android, it says “android:comand not found”
what should i do?
*sorry for my bad english.
That’s because .bashrc has nt been updated correctly. Please check the paths.
okay… i only export paths via terminal…
problem solved…
thank you
Dear Dasun,
I got error as “bash: /usr/local/android-sdk-linux/tools/android: Permission denied”. What I do ?
try with sudo
When I try with sudo get as
sudo: android: command not found
That’s because you haven’t set the paths in .bashrc for sudo
Thanks Dasun ,
$ sudo -s
command do the trick…
For others: when you are using zsh instead of bash for example, edit ~/.zshrc instead.
Hi, thanks for offering your wisdom. I cannot get my
phonegap app to install – the error is Failure
[INSTALL_FAILED_UPDATE_INCOMPATIBLE] – the target is a device
running Android 5.1.1, but “phonegap platform list” only shows
android 4.1.1. when I attempt to run “phonegap platform add
android@5.1.1 I get an error
“Failed to fetch
platform android@5.1.1
Probably this is
either a connection problem, or platform spec is incorrect.
Check your
connection and platform name/version/URL.
Error: version not
found: cordova-android@5.1.1”
what should I try to
get this app to install?
Try this
http://stackoverflow.com/questions/11891848/install-failed-update-incompatible-when-i-try-to-install-compiled-apk-on-device
Thank you for that, but I tried every way from Sunday to make sure the app wasn’t already installed – wasn’t until I started using the phonegap build utility that I could get the app to install and run. that utility is a little inconvenient, I might come back to the command line some time in the future.
i have followed your instructions.. i have installed evrything andriodsdk, emulator, phonegap and everything else you mentioned.. but when i give “phonegap” to test its installed, nothing happened.. not just that one alone, but every command which inculdes phonegap like “phonegap platform -ls” ther goes, nothing happen.. if i give commands its just goes to next line.. thats all.. im usint ubuntu 14.04
i have followed your instructions.. i have installed evrything andriodsdk, emulator, phonegap and everything else you mentioned.. but when i give “phonegap” to test its installed, nothing happened.. not just that one alone, but every command which inculdes phonegap like “phonegap platform -ls” ther goes, nothing happen.. if i give commands its just goes to next line.. thats all.. im using ubuntu 14.04
I tried installing cordova, nodejs, npm and phonegap on 14.04 and I could not get it to to work no matter how hard I tried. I upgraded to 15.10 (latest) and I installed cordova, nodejs and npm following this link http://jeffmcmahan.info/blog/installing-cordova-on-linux/ . And followed this tutorial without so much as a drop of sweat! Back up and save all your data because I had a problem upgrading from 14.04 to 15!
Pingback: Are there any simple PhoneGap tutorials? | Some Cordova Questions and Answers
I finished until set up #6 but then i get an error at #7 when i typed the command “phonegap create testapp”
It throws an error:
module.js:340
throw err;
^
Error: Cannot find module ‘bplist-parser’
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object. (/usr/local/lib/node_modules/phonegap/node_modules/cordova/node_modules/cordova-lib/node_modules/cordova-common/src/ConfigChanges/ConfigFile.js:20:14)
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)
at Module.require (module.js:364:17)
Please help. Thanks
Try this link…
http://askubuntu.com/questions/724863/how-can-i-fix-the-cannot-find-module-bplist-parser-error-with-phonegap
if we’re running 64bit ubuntu should those packages be the 64bit versions? why 32?
You have to run:
$ sudo apt-get install libz1 libncurses5 libbz2-1.0 libstdc++6
Dear friends,
when I try to run (on my ubuntu 15.10)
root@insight:~/testapp# cordova run android
ERROR running one or more of the platforms: Android SDK not found. Make sure that it is installed. If it is not at the default location, set the ANDROID_HOME environment variable.
You may not have the required environment or OS to run this project
as error . Please advise
Thanks
I’m confused … Why is this all geared towards android? Like why are we using an android-sdk and such? Is that just for testing purposes? Could this just as easily be geared towards ios or another platform? I thought that was the point of phonegap.. It would have been helpful if you talked about that on some level
i am getting thiis error when i try to build:
Error: Failed to run “java -version”, make sure that you have a JDK installed.
You can get it from: http://www.oracle.com/technetwork/java/javase/downloads.
Hi, I am developing and mobile app with phonegap,
I will use android-sdk , and I installed it, but it has many many packages, which are the minimum necessary? do they depend on my hardware? 64bit i5 ?
Surely I will try this method. Good information. Thank you very much dear admin.
English grammar
Pingback: Computer doesn't recognise file – 1OO Club