In this guide we will see what is phonegap and how to start using it on ubuntu.
What is 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”
Native apps are developed using platform specific programming language and SDK of the platform. So if you are developing a native app for android you would use Java and use Android SDK, similarly for iOS would require C#/Swift and iOS SDK. This means for each platform the app would need to be developed from scratch and maintained/updated separately. This require large scale investment in terms of developers, maintenance, time frame etc even for a small app. But the plus point is you can develop high performance app and easily access phone native features.
What i mean by native phone feature are things like accessing Network Status, GPS, Contacts, File Transfer, NFC, Camera, Battery Status, Back Button and other such things which are critical for app building.
So problem with native app is maintain different code base for each platform and require expertise in different programming languages, but the plus point being better performance. So to overcome this problem, the concept of hybrid was introduced.
Develop once and deploy access multiple platforms.
Reduces development cost and time a lot.
Slower Performance Compared Native Apps
Lacks Native look and feel.
Not recommend for high performance applications.
In the end my take is, with the exponential increase in mobile computing power (processor speed, ram, graphics, etc) the performance of hybrid apps would soon become negligible compared to native apps.
Getting Started On Ubuntu/Centos For Android
Install nodejs and npm. For Ubuntu
curl -sL https://deb.nodesource.com/setup | sudo bash -
sudo apt-get install nodejs
sudo apt-get install build-essential
After this to install phonegap run
sudo npm install -g cordova
Next to run the project on android, we need to install the android SDK. There are various ways to do it
First step is to install java
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java7-installer
Next to install SDK
Download from here http://developer.android.com/sdk/index.html#Other. Copy the zip file to /var folder so your android SDK folder will be “/var/android-sdk-linux”
Next run this command
sudo chmod +x android
This should start the android sdk and you can download platform tools from here. If your not an expert simply press install or you can choose the specific packages from here (Just install the latest API and uncheck any JDK Sample and Docs).
Once this is done you need add tools/ folder to your class path. For this
Next install “ant”
sudo apt-get install ant
The above completes the process of installing android sdk. Next to create your first phonegap project go to your development folder “/var/www/html”
phonegap create hello com.example.hello HelloWorld
//com.example.hello is your package name. this is very important so keep a note of it
phonegap platform add android
phonegap build android
At this point the build should be successful and your android app is ready. To deploy the app on your phone, first enable developer mode on your android phone through steps mentioned here and enable usd debugging. Next run
phonegap run android
Your hello world app should now run on your device.