Phonegap/Cordova Android Development

PhoneGap/Cordova Android Development

It's possible that the Android tools binaries are not in your path.

According to the PhoneGap docs (http://docs.phonegap.com/en/2.9.0/guide_getting-started_android_index.md.html), you need to include the Android SDK's tools and platform-tools in your PATH environment variable.

export PATH=${PATH}:/Development/adt-bundle/sdk/platform-tools:/Development/adt-bundle/sdk/tools

where Development is the path you installed your SDK.

Phonegap / Cordova - Build Apk

To check whether or not you have everything installed that is required to build an APK first run this command:

$ cordova requirements

This should give something similar to the following result:

Requirements check results for android:
Java JDK: installed .
Android SDK: installed
Android target: installed android-19,android-21,android-22,android-23,Google Inc.:Google APIs:19,Google Inc.:Google APIs (x86 System Image):19,Google Inc.:Google APIs:23
Gradle: installed

You need to make sure that you have the latest Java JDK installed and the Android SDK. You will also need to make sure that Java is in you computer's PATH.

Then you can run this command:

$ cordova build android

Follow this guide:

https://cordova.apache.org/docs/en/latest/guide/cli/

How to make PhoneGap - Android set up process as one step build?

I would recommend to use the command line tool to build your project, so it can be used easily for all your members of your team.

1) Commit the appropriate files in your source control

  • www folder (mandatory)
  • config.xml (mandatory)
  • hooks ( if used )
  • merges ( if used )

The rest should be ommited from your source control as it will be generated each time you build your project.

2) Each developer will have to add the platform he wants to build the app.

 cordova platform add android
cordova platform add ios

This step will create a platform(android, ios ...) in your platform folder with all the files needed for cordova to package it.

3) Add the necessary plugins for your app (exemple below)

cordova plugin add org.apache.cordova.device

This will add the plugin in your plugin folder as well as updating automatically your AndroidManifest.xml located in your platform/android/AndroidManifest.xml. Usually, permissions in AndroidManifest.xml will be added automatically by the plugins. You should never update AndroidManifest.xml manually

By the way, I would recommend to implement a hook mechanism to add plugins automatically when adding a platform, so your members of your team won't have to do the step 3. Here is the way to do it nicely

EDIT: Since cordova 3.5.0, we can define plugins to be used in config.xml like below:

<feature name="Network Information">
<param name="id" value="org.apache.cordova.network-information" />
<param name="version" value="0.2.10" />
</feature>

And restore them automatically with:

cordova restore plugins --experimental

As a matter of fact, we don't need to have hooks or add plugins manually
END EDIT

Build the project for Android

cordova build android

This command is the shorthand for cordova prepare android && cordova compile android
This will package your project into a nice file ready to deploy in platforms/android/ant-build/

How to use PhoneGap Developer App in Cordova projects

You have to install PhoneGap npm install phonegap -g and then you can call phonegap serve on your Cordova-project.

Difference between PhoneGap and Cordova and which one should we install?

OK, to put it simple:

PhoneGap - The original project developed by volunteers

Cordova - The Apache's version of Phonegap, which has exactly the same documentation and functionality as the original PhoneGap but is integrated in NetBeans 7.4.

Developing in Android Studio versus Framework (e.g PhoneGap)

I have developed apps for both Android and Phonegap. Phonegap takes advantage of your web development experience and lets you build mobile apps with ease. But it's not a replacement for Android API itself. A good phonegap application requires knowledge about web development and Android API.

However if your aim is to develop an android application, and you are comfortable with web development and Android, I would advice to take Android API.

Phonegap as wonderful as it is for web developers, and startups who can't afford to have dedicated resources for Android, iOS separately, has its limitations.

  • Performance : Phonegap app's performance is not at par with a native
    android application.
  • Functionality : As one would expect you can't have all the functionality support a native android application has.
  • Look : You could easily tell apart a phonegap application from a native one. Given phonegap renders all the content in a webview, the look of native ui elements is lost

Phonegap/Cordova build android node_modules/q/q.js throw e;

I noticed that your ANDROID_HOME variable might be incorrectly setup - as far as I can tell, it should be set to the root of your SDK folder (what you have ANDROID_SDK set to), try that (and make sure that you still have both $ANDROID_HOME/tools and $ANDROID_HOME/platform-tools on your path).



Related Topics



Leave a reply



Submit