HomeMobile AppsPhonegap – Getting Started On Ubuntu For Android

Phonegap – Getting Started On Ubuntu For Android

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”

PhoneGap is a javascript based library to create hybrid mobile apps. Hybrid apps are mobile app which are built using HTML,CSS and can access native features of phone through javascript. Lets see further in detail what are hybrid apps. But to understand hybrid apps, lets first see what are native apps.

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.

Hybrid Apps are a bridge native apps and html/css apps. Every platform SDK exposes a WebView object (android, ios, windows) which basically a mini browser inside a mobile app. So with web view you are able to implement all HTML/CSS/Javascript inside an app. All UI/UX/Events of an app can be easily managed inside a webview and you can use any of your favorite library like jQuery, Angular etc to implement these. Next comes the need to access a phones native features through web view, here is where framework like phonegap come into play.

Phonegap provides javascript based libraries through which we can access native phone features. Phonegap maintains a platform specific library for each platform (android, ios, windows, blackberry, fireos etc) and provides you with a common set of java script libraries to access native feature. This allows developers to have a single code base using single language (html/css/java-script) for all platforms plus we can access all native features as well. The only drawback is performance. Since everything runs on top of WebView, phonegap applications are generally slower and lack native look/feel.

PhoneGap Pros:
1. Single Code Base for your app across platform using only html/css/javascript.
2. Develop once and deploy access multiple platforms.
3. Reduces development cost and time a lot.

PhoneGap Cons:
1. Slower Performance Compared Native Apps
2. Lacks Native look and feel.
3. 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
cd /var/android-sdk-linux/tools
sudo chmod +x android
sudo ./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
vi ~/.bashrc
export PATH=${PATH}:/var/android-sdk-linux/tools
export PATH=${PATH}:/var/android-sdk-linux/platform-tools
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
cd hello
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.

%d bloggers like this: