Basic PhoneGap Android app from scratch step-by-step

This tutorial assumes that you have eclipse which is set up for regular android development and you can create new android projects. Phonegap files are now named cordova

  1. Create new Android project in eclipse.
  2. Download package and extract cordova-2.6.0.jar  from zip file from
  3. Add cordova-2.6.0.jar to your projects build path. In eclipse open project properties > Java Build Path > Add Jars
  4. Change main Activity superclass to DroidGap
  5. Replace setContentView(R.layout.main); with super.loadUrl(“file:///android_asset/www/index.html”);
  6. Create folder xml into the project res folder. Add there plugins.xml and cordova.xml from the package you download before.
  7. Add into AndroidManifest.xml <uses-permission android:name=”android.permission.INTERNET” /> and     <uses-permission android:name=”android.permission.ACCESS_NETWORK_STATE” />
  8. Create folder www into projects assets folder.
  9. Add index.html file into assets/www. File content is regular HMTL.

By now you can already run the program. Next steps are starting to use PhoneGap special HTML5 features and try accessing hardware. If It fails to run then make sure you have logcat view activated in eclipse or try in linux commandline:

./adb logcat


 W/System.err(24831): ERROR: plugin.xml is missing.  Add res/xml/plugins.xml to your project.
 Make sure you have plugins.xml in projects res/xml folder.


 W/System.err(24831): Permission denied
 W/System.err(24831):     at org.apache.harmony.luni.platform.OSNetworkSystem.socket(Native Method)
 W/System.err(24831):     at dalvik.system.BlockGuard$WrappedNetworkSystem.socket(
 W/System.err(24831):     at
 W/System.err(24831):     at
 W/System.err(24831):     at<init>(
 W/System.err(24831):     at<init>(
 W/System.err(24831):     at
 W/System.err(24831):     at
 Add <uses-permission android:name="android.permission.INTERNET" /> permission


E/AndroidRuntime(24831): FATAL EXCEPTION: main
E/AndroidRuntime(24831): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mobiwsale.client/com.mobiwsale.client.MobiwsaleClientActivity}: android.content.res.Resources$NotFoundException: Resource ID #0x0
E/AndroidRuntime(24831):     at
E/AndroidRuntime(24831):     at
E/AndroidRuntime(24831):     at$1500(
E/AndroidRuntime(24831):     at$H.handleMessage(
E/AndroidRuntime(24831):     at android.os.Handler.dispatchMessage(
E/AndroidRuntime(24831):     at android.os.Looper.loop(
E/AndroidRuntime(24831):     at
E/AndroidRuntime(24831):     at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(24831):     at java.lang.reflect.Method.invoke(
E/AndroidRuntime(24831):     at$
E/AndroidRuntime(24831):     at
E/AndroidRuntime(24831):     at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(24831): Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x0
E/AndroidRuntime(24831):     at android.content.res.Resources.getValue(
E/AndroidRuntime(24831):     at android.content.res.Resources.loadXmlResourceParser(
E/AndroidRuntime(24831):     at android.content.res.Resources.getXml(
E/AndroidRuntime(24831):     at com.phonegap.api.PluginManager.loadPlugins(
E/AndroidRuntime(24831):     at com.phonegap.api.PluginManager.<init>(
E/AndroidRuntime(24831):     at com.phonegap.DroidGap$
E/AndroidRuntime(24831):     at
E/AndroidRuntime(24831):     at com.phonegap.DroidGap.loadUrlIntoView(
E/AndroidRuntime(24831):     at com.phonegap.DroidGap.loadUrl(
E/AndroidRuntime(24831):     at com.mobiwsale.client.MobiwsaleClientActivity.onCreate(
E/AndroidRuntime(24831):     at
E/AndroidRuntime(24831):     at
E/AndroidRuntime(24831):     ... 11 more
Check plugin.xml and phonegap.xml files in res/xml
D/DroidGap(24990): DroidGap: GapViewClient.onReceivedError: Error code=-14 Description=The requested file was not found. www/index.html URL=file:///android_asset/www/index.html
add index.html to to folder assets/www

E/AndroidRuntime( 4320): java.lang.RuntimeException: Error receiving broadcast Intent { flg=0x10000000 (has extras) } in org.apache.cordova.NetworkManager$1@4053d928
Add <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> permission

See also

5 thoughts on “Basic PhoneGap Android app from scratch step-by-step

  1. Pingback:Add Facebook login to PhoneGap Android app Easiest way « Margus Pala is fixing IT!

  2. Pingback:PhoneGap vs native Android and iPhone app performance and features « Margus Pala is fixing IT!

  3. Pingback:PhoneGap application crashing when rotating « Margus Pala is fixing IT!

Leave a Reply

Your email address will not be published.