Getting Started With Phonegap CLI

About PhoneGap

PhoneGap is a free and open source framework that allows you to create mobile apps using the web technologies you’re already familiar with: HTML, CSS, and JavaScript. The beauty of PhoneGap is that you’re able to reuse your existing web developer skills so you have a shorter learning curve and faster development. You can compile your codes into numerous mobile platforms including iOS, Android, Windows Phone and BlackBerry using the Phonegap build tool.

Phonegap CLI

The Phonegap Framework command line utility makes it easy to start, build, run, and emulate mobile apps.

 

Install the Phonegap CLI

Getting started with Phonegap CLI that require node.js, together with git.

The easiest way to get the Phonegap CLI is through npm.

$ npm install -g phonegap@latest

Following installation, you should be able to run phonegap on the command line with no arguments and it should print help text.

phonegaptute1

Create your first app

Go to the directory where you maintain your source code, and create a phonegap project:

Enter the following command from your terminal:

$ phonegap create hello com.example.hello HelloWorld

This command will create a subdirectory, named hello, to hold our application files and to establish a new application named HelloWorld, with an com.example.hello namespace.

Build the Android App

Simply run one command for the node package manager to install PhoneGap’s tools:

$ npm install -g cordova

To be able to build for the Android platform, the Android SDK must be installed on your system. The Android SDK is available here.

On the command line, make sure you are in the hello directory and type:

$ cordova platforms add android

Test the App

SDKs for mobile platforms often come bundled with emulators that execute a device image, so that you can launch the app from the home screen and see how it interacts with many platform features. Run a command such as the following to rebuild the app and view it within a specific platform’s emulator:

$ cordova emulate android

Serve an App

Preview your first app in a Desktop Browser you should be able to run $ phonegap serve on the command line into the project directory.

phonegaptute2

 

Build android release apk on Phonegap CLI

On the command line, make sure you are in the hello directory and type:

$ Run build –release.

Android Example : cordova build –release android

This creates an unsigned release APK at /path/to/your/project/platforms/android/bin folder, called HelloWorld-release-unsigned.apk.

 

Read More:

PhoneGap Documentation
Apache Cordova Documentation

PhoneGap and Cordova has made creating a mobile app easy to follow. We can build a mobile app like we build a website. Alas I hope that this post can help you get started on using PhoneGap for developing mobile app.

2 thoughts on “Getting Started With Phonegap CLI

Leave a Reply

Your email address will not be published. Required fields are marked *