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:
- iOS
- Android
- Windows Phone
- Windows
- Firefox OS
- Amazon Fire OS
- 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
- Download and install node.js, This will be used to install the Cordova/PhoneGap framework.
- Download and install a Git Client, This is used by the Cordova/PhoneGap framework when creating projects.
- Open command prompt and verify that both of the above systems have been installed by running npm and git.
- Install the Cordova/PhoneGap system by running the following command in your command prompt (Note: this may take a few minutes)
C:\>npm install -g cordova
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
- Create a directory which will contain your PhoneGap/Cordova project code.
- Open the created directory in command line and create a project with the command cordova create < sitename >
C:\>rootdir\cordova create FirstSite
-
This will create a project in the root folder with the specified site-name. This project will contain:
- "hooks" directory- Contains special scripts that can be used to customize Cordova commands.
- "platforms" directory- This contains the app specific projects that you will include below.
- "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.
- "www" directory- Contains the PhoneGap/Cordova structure and some standard js and css files.
- config.xml file- This file contains meta data for controlling common features of your apps like the app title, description and author.
-
Add platforms to the project with the cordova platform add
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
C:\>rootdir\cordova platform add android
-
You can now get a list of the added platforms by running the following command:
C:\>rootdir\cordova platform ls
-
You can remove a specific platform from the list with the following command:
C:\>rootdir\cordova platform remove android
- 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
C:\>rootdir\cordova build
- You can use these built projects found in the "platforms" directory in platform specific IDEs or emulate the projects directly with the following command:
C:\>rootdir\cordova emulate android
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.