Using the PhoneGap CLI

iconTo date, we’ve encouraged our users to use PhoneGap Build to make their native apps. It’s quick, easy to use and meets the needs of most users. PhoneGap Build is a wrapper built on top of the open source Cordova engine. PhoneGap CLI lets you work directly with Cordova, which has a few advantages:

  • Build takes place on your local machine – no uploading to a service
  • Free – PhoneGap CLI is open source.
  • No limit on number of projects
  • Use the latest plugins: Sometime developers have newer versions of their plugin that are not in PhoneGap Build yet.
  • Use PlugIns which are not in PhoneGap Build at all.
  • Use custom PlugIns you have developed yourself.

But there are a few downsides too:

  • Much more complicated to get working
  • More difficult to use
  • More difficult to sign apps for release
  • A Mac is needed to build for iOS (not just for submission to the iTunes Store)

The first step in using the PhoneGap CLI is to install the toolchain. You’ll need to install Node.js, the Android SDK, the Java Development Kit, Apache ANT and Cordova. You’ll find more information about the in the PhoneGap CLI Tech Note. This will be hardest part. If you want to build for both Mac and PC, you will have to do all this on both environments.

Once this is done, you need to add the PhoneGap CLI files to your project folder. This part is easy: enter the following from the command line:

cordova create phonegap com.example.HelloWorld HelloWorld
cd phonegap
cordova platform add android

Next, add any plugins you need:

cordova plugin add

This will add the plugin files to your project.

Finally, choose “Build Native App with PhoneGap CLI” in AppStudio’s Run menu. It will build the app and run it on a connected Android device or in the emulator.

There is a lot of customization which can be done. You can add your own icons, splash screens and control a myriad of options by modifying the files in the phonegap directory in your project folder. Complete information is on PhoneGap’s site.