Trying PhoneGap to build an Android App

PhoneGap can be seen as a framework to port web applications to native apps, as we know for web applications are developed by HTML or JavaScript, and android apps usually developed with Java. As far as I concerned, PhoneGap is a develop framework which we can use HTML or JavaScript to develop applications, and through transform, this application could run directly on android devices or Eclipse with Android Environment.

So in other words, it’s kind like using HTML and JavaScript to develop Android application, so the idea for the “MediaGrid” project is that we can port the JavaScript code to the Android using PhoneGap. To check whether this idea work, I wrote a small example to see whether we can port the web applications to native apps using the PhoneGap. The example is as followed:

1. Android Environment Preparation. In order to develop Android application, you’ll need JAVA Development Kit(JDK), Eclipse, Android Software Development Kit(Android SDK).
a) JDK can be accessed from JDK, and latest version is JAVA 8. After installation, use java -version in CommandLine to check if it is properly installed.
b) Eclipse  can be downloaded at Eclipse. Android SDK ADT Bundle for Windows already include everything for Android development: latest Android SDK, Eclispe, Android Emulator, Android SDK and Platform tools.

2.PhoneGap Environment Preparation.
a) Before installing PhoneGap, you should first install NodeJS . Use npm -v to check if nodejs is properly installed.
b) PhoneGap can be installed simply by:
       npm install -g phonegap
Use phonegap -v to check the version of it.

c) In order to use cordova utility, Android SDK platform tool and Android SDK tool should be added into system PATH. On Windows, just append environment variable PATH with “/Development/adt-bundle/sdk/platform-tools:/Development/adt-bundle/sdk/tools”.
d) Create app with cordova.
$ cordova create hello com.example.hello “HelloWorld”
$ cd hello
$ cordova platform add android
$ cordova build

3. Edit and run application in Eclispe. 
a) Lunch Eclipse and choose File->Import->Existing Android Project. Set file path to the directory of hello project. And both hello and  hello-CordovaLib should be selected, and choose Finish. 
b) Click Run->Run as Android Application. Then there’ll be a dialog to decide a device for application to run on, then just choose your android phone or android emulator.

 Here shows the result of hello running on my phone:


To conclude, we can use the PhoneGap’s tool cordova to create a Android project (HTML and JavaScript is automatically generated) and then import to Eclipse with Android Environment. In this process, I’ve found that in PhoneGap we can use Angular JS directly, which means for the MediaGrid project, it will bring us great convenience, and using PhoneGap to create application has a great advantage that is it can support diverse platform, like Android device, Android simulator, ios device and blackberry device.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s