Friday, August 29, 2014

Using PhoneGap CLI commands


PhoneGap V3.0 and later includes a CLI (Command Line Interface) that provides a suite of commands a developer can use to manage the complete lifecycle of an application.
This article explains the CLI commands and their usage.


To use CLI commands, you need to install PhoneGap first and then SDKs for each platform you wish to target.
To install PhoneGap visit : http://www.markupjavascript.com/2014/07/installing-phonegap-in-windows.html
To know about Tools required to develop PhoneGap/Cordova App visit : http://www.markupjavascript.com/2014/01/tools-required-to-develop-hybrid-mobile-app.html
For platform guides visit : http://docs.phonegap.com/en/3.5.0/guide_platforms_index.md.html#Platform%20Guides

On windows, CLI can be accessed from command prompt and in Mac, from terminal.

CLI Commands and their usage :

Creating a PhoneGap Project
- Open Command Prompt with Admin rights
- Go to the directory where you want to create the project and run command :
phonegap create project_folder app_id app_name

for eg : phonegap create hello com.example.hello HelloWorld
"hello" specifies a directory to be generated for your project.
"com.example.hello" (optional and can be changed later in config.xml) provides your project with a reverse domain-style identifier.
"HelloWorld" (optional and can be changed later in config.xml) provides the application's display title


Platform Management

Adding Platforms
- Go to the project's directory and run command :
phonegap platform add platform_name

for eg. to add android platform : phonegap platform add android
This command will download the folder structure and required files to your project directory for the added platform.
You can now open the files in any IDE for editing.

Removing Platforms
cordova platform remove platform_name
This command will download the folder structure and required files to your project directory

Note : If you get an error : "error 'platform add android' is not a phonegap.js command " then directly try build command given below for that specific platform ie. phonegap build platform_name


Plugin Management

Search Plugin
cordova plugin search <search term>

Add Plugin
cordova plugin add <plugin>

List all Plugins installed
cordova plugin ls
cordova plugin list

Remove Plugin
cordova plugin rm <plugin>
cordova plugin remove <plugin> 


Build Management

Build
- Go to the project's directory and run command :
phonegap build
This will build the project for all the added platforms.

To build a specific platform use
phonegap build platform_name
for eg. to build android platform : phonegap build android
The phonegap build command is a shorthand for the prepare and compile commands

Prepare
The CLI prepare command copies a PhoneGap project’s web application content from the www and merges folders into the appropriate platforms folders for the project.

Compile
The compile command initiates a compilation process by calling the build script for one or more mobile platforms.


Running Applications
The CLI has built-in integration with mobile device platform simulators, so you can launch PhoneGap applications directly onto simulators or physical devices.

Emulate
- Go to the project's directory and run command :
phonegap emulate platform_name

for eg. to emulate android platform : phonegap emulate android
The CLI emulate command automates the process of building an application and deploying it onto a mobile device simulator. The command first prepares the application, executes the build process, then deploys the resulting native application package to the simulator.

Run
- Plug the handset into your computer
- Go to the project's directory and run command :
phonegap emulate platform_name

The CLI run command automates the process of building an application and deploying it onto a physical device. The command first prepares the application, executes the build process, then deploys the resulting native application package to a connected device.

To know more about Cordova/PhoneGap CLI (Command Line Interface) after V3.0 visit : http://www.markupjavascript.com/2014/02/cordova-cli-command-line-interface.html
To know more differences about Cordova/PhoneGap before and after v3.0 visit : http://www.markupjavascript.com/2014/02/apache-cordova-before-and-after-v3.html

It is recommended that you review the Platform Guides for the mobile platforms that you will be developing for.

Related Posts Plugin for WordPress, Blogger...

Receive all updates via Facebook. Just Click the Like Button Below

You can also receive Free Email Updates: