Engineering Blog

Getting Started with Phonegap

PhoneGap now also known as Apache Cordova, is a powerful tool for mobile development which allows you to develop in HTML/JS markup and quickly generate out various mobile compatible apps. This prevents your developers from having to learn and understand multiple platform specific languages and instead use the PhoneGap framework which is based in HTML to create the app and then generate it into any one of the following platforms:

  1. iOS
  2. Android
  3. Windows Phone
  4. Windows
  5. Firefox OS
  6. Amazon Fire OS
  7. Blackberry

With time saved on learning development languages for the above platforms your team can focus on the features of your app.

Setting up your Environment

  1. Download and install node.js, This will be used to install the Cordova/PhoneGap framework.
  2. Download and install a Git Client, This is used by the Cordova/PhoneGap framework when creating projects.
  3. Open command prompt and verify that both of the above systems have been installed by running npm and git.
  4. Install the Cordova/PhoneGap system by running the following command in your command prompt (Note: this may take a few minutes)

Verify your installation of Cordova/PhoneGap by running cordova in command prompt. This should display a list of the available Cordova commands.

Setting up your Project

  1. Create a directory which will contain your PhoneGap/Cordova project code.
  2. Open the created directory in command line and create a project with the command cordova create <sitename>
  3. This will create a project in the root folder with the specified site-name. This project will contain:
    1. “hooks” directory- Contains special scripts that can be used to customize Cordova commands.
    2. “platforms” directory- This contains the app specific projects that you will include below.
    3. “plugins” directory- Contains add-on code for interfacing with native features. You can create your own custom interface or use one of pre-compiled plugins.
    4. “www” directory- Contains the PhoneGap/Cordova structure and some standard js and css files.
    5. config.xml file- This file contains meta data for controlling common features of your apps like the app title, description and author.
  4. Add platforms to the project with the cordova platform add <platform> command.
    Note: adding platforms requires that the relevant dependencies are installed in your system for example adding android requires that you have installed the Android SDK.Available platforms for a windows environment are:

    • wp7
    • wp8
    • windows8
    • amazon-fireos
    • android
    • blackberry10
    • firefoxos

    And for Mac:

    • ios
    • amazon-fireos
    • android
    • blacberry10
    • firefoxos
  5.  You can now get a list of the added platforms by running the following command:
  6. You can remove a specific platform from the list with the following command:
  7. Once you have added in the desired platforms build the platform specific apps by running the following command:
    Note: Building platforms requires that the relevant dependencies are installed in your system for example building android requires that you have installed the Android SDK.

  8. You can use these built projects found in the “platforms” directory in platform specific IDEs or emulate the projects directly with the following command:

At this point you have a basic PhoneGap project configured and your desired platforms added and you can get started with adding or building out additional features and content in the “www” directory and run the command in step 7 above to create the platform specific projects. You can find detailed instructions on setting up additional features and implementing PhoneGap on the  PhoneGap site.

Related Posts