FreeSoft
English EN

Getting started

Getting started with PhoneGap

Understand the original installation and first-project workflow, with clear guidance for existing projects.

Restored guides + editorial notesHistorical reference
Archive note. Historical reference. PhoneGap tools and the former Adobe services are no longer maintained as described in the original material. Recovered text and newly written explanations are identified below; consult current platform documentation for active development.

Choose a workflow

Historically, PhoneGap Desktop offered a graphical workflow and PhoneGap CLI offered a terminal workflow. Both could serve a project for preview in the Developer App. Packaging a distributable application was a separate step, using platform tooling or the former Build service.

For a new maintained application, begin with Apache Cordova’s current setup guide. The instructions below preserve the original PhoneGap workflow for readers maintaining or researching an existing project.

Install the command-line tools

Original archive text

The PhoneGap CLI provides a command line interface for creating PhoneGap apps as an alternative to using the PhoneGap Desktop App for those who prefer working at the command line. The PhoneGap CLI currently has some additional features over the PhoneGap Desktop for building, running and packaging your PhoneGap applications on multiple platforms. If you're comfortable using a CLI this option may be best going forward.

**NOTE:** The getting started steps vary based on the initial PhoneGap tool you install here in step 1. For the rest of the steps be sure to choose either the **Desktop** or **CLI** tab at the top accordingly.

Requirements

There are a few simple requirements you'll need prior to installing the PhoneGap CLI:

  • node.js - a JavaScript runtime to build your JavaScript code
  • git - used in the background by the CLI to download assets. It comes pre-installed on some operating systems.

To see if you already have it installed, type git from the command line.

Install Steps

  1. Install the PhoneGap CLI via npm with the following command from the Terminal app (Mac) or Command Prompt (Win).
$ npm install -g phonegap@latest
**TIPS:** 1) The `$` symbol is used throughout this guide to indicate the command prompt, it should not be typed. 2) `npm` is the node package manager and installed with node.js. The `npm` command fetches the necessary dependencies for the PhoneGap CLI to run on your local machine. It creates a *node_modules* folder with the necessary code needed to run the CLI. The `-g` flag specifies that folder to be installed at the global location so it can be accessed from anywhere on your machine (defaults to */usr/local/lib/node_modules/phonegap* on Mac).
**OS X Users:** You may need to prefix this command with `sudo` to allow installation to restricted directories and type the following instead: `$ sudo npm install -g phonegap@latest`

**Windows 8 Users:** If you just installed Node.js, be sure to start the *Node.js Command Prompt* application specifically.
  1. Test to ensure the PhoneGap CLI is properly installed by typing phonegap on the command line. You should see the following help text output displayed:
$ phonegap
Usage: phonegap [options] [commands]
Description:
 PhoneGap command-line tool.
 Commands:
    help [command]       output usage information
    create <path>        create a phonegap project
     ...
**TIP:** You can access the PhoneGap CLI usage text at any time by adding the keyword `help`, or the `-h` or `--h` attribute with any phonegap command i.e.: `$ phonegap create help`, `$ phonegap serve -h`.

Create your first project

Original archive text

Now that you've installed PhoneGap Desktop and/or the PhoneGap CLI

Create Default PhoneGap Project

The PhoneGap CLI has a default Hello World project for beginners to start with. It's proven to be the quickest and easiest way to understand the basics of building a mobile PhoneGap app so let's start by creating the default project with the CLI.

  1. Enter the following command from your terminal:
$ phonegap create myApp

This will create a folder named myApp in the current path location with a default project name of Hello World and id of com.phonegap.helloworld.

You can also specify a name and identifier to ensure the project is unique but still contains the default Hello World code project by specifying them as qualified parameters as shown below:

$ phonegap create myApp --id "org.myapp.sample" --name "appSample"
**TIP:** Each of the `create` command options is documented in the help text and can be accessed with `$ phonegap create help`. To access general help from the CLI, type `-h` or `help` with any command.
  1. Verify that you see the following output in your console after you run the command:
Creating a new cordova project.
  1. Change into the new project directory with the cd command:
$ cd myApp/
  1. Check to be sure you see the following set of files and folders shown below:
config.xml    hooks    platforms    plugins    www
  1. cd into the www folder and look around at the files and subfolders in there, this is the content of your app, with the entry point being the index.html file.
$ cd www/
**TIP:** Details about the rest of the files and folders created in the root project will be covered in guides further along. For now just focus on the ***www*** folder and its contents.

Preview the project

Original archive text

The PhoneGap CLI has a serve command that starts a small web server to host your project where it can then be consumed by the PhoneGap Developer App running on a mobile device or your desktop browser.

Preview in a Desktop Browser

You can test your apps in your desktop browser first to speed up your initial development process. For instance, if you're using a framework like Angular or React, there are tools available for specifically debugging those frameworks in the browser that can be quite helpful before moving over to a device. Recently PhoneGap began supporting the browser platform as a target automatically to help you test with the deviceready event and Apache Cordova core plugins more easily in an environment you're already familiar with.

Historical illustration from the original documentation

Refer to the PhoneGap Browser Support Reference guide for specific details.

Preview on a Device

You can use the PhoneGap Developer App paired with the PhoneGap CLI to immediately preview your app on a device without installing platform SDKs, registering devices, or compiling code. The PhoneGap CLI starts a small web server to host your project and returns the server address for you to pair with from the PhoneGap Developer App running on your mobile device.

Double check to ensure you're running your device and computer on the same network before continuing.
  1. cd into the project directory created in the previous step and type $ phonegap serve. You will receive the server address the app is being hosted on in the output received in the console (192.168.1.11:3000 in this example):
$ phonegap serve
[phonegap] starting app server...
[phonegap] listening on 192.168.1.11:3000
[phonegap]
[phonegap] ctrl-c to stop the server
[phonegap]
  1. Now go to your mobile device where the PhoneGap Developer App is running, enter the server address on the main screen and tap Connect.
PhoneGap Developer App, iOS
**NOTE:** Tap directly on the server address displayed in the terminal screen of the PhoneGap Developer app to change it to match yours. The value filled in by default is only a sample.

You should see the connection occur followed by a success message as shown below. If you receive an error of any kind, ensure once again that you are connected to the same network on both your device and your computer. You could also check the issue tracker and PhoneGap Google Groups list for further help.

Developer App, connection success

Once the PhoneGap Developer app connects and loads your mobile application, it should be displayed for preview as shown below:

Developer App, preview
**TIP:** Gestures can be used while you're previewing your app. A 3 finger tap will return you to the main screen, a 4 finger tap will cause a refresh.

Making Updates

  1. Now let's make an update to some code to see how easy it is to test changes. Using your favorite text editor, open up the index.html file located within the www folder of your project; for instance ~/appSample/www/index.html
**TIP:** Some popular lightweight but powerful editors include [Brackets](http://brackets.io/), [Sublime Text](http://www.sublimetext.com/), [Atom](https://atom.io/) and [Code](https://www.visualstudio.com/products/code-vs.aspx). If you're looking for more of an IDE with extensive features and plugins including code hinting and type-ahead, check out [WebStorm by JetBrains](https://www.jetbrains.com/webstorm/)
  1. Choose an update to make. Let's start by changing the PHONEGAP text that's displayed in the app from <h1>PhoneGap</h1> to <h1>Hello PhoneGap</h1>. (This text has a CSS uppercase transform applied to it in the default project). Save it when you're finished and move on to the next step. Historical illustration from the original documentation

  2. Now check your mobile device where your PhoneGap Developer app is running and you will see your app reload and automatically display the new text!

Developer App update preview ![](/images/phonegap-app-developer-workflow-v2.gif)
  1. Continue making updates to your project to get familiar with this workflow.

At this point you should check out this guide explaining important details about the default Hello PhoneGap application and mobile application development tips with PhoneGap in general.

Prefer a graphical installer?

Read the Desktop installation archive and use the official release archive. The Desktop instructions are historical and may refer to operating systems and download locations that are no longer supported.

Move an existing application forward

Preserve the app identifier, web assets, plugin list and signing records. Compare each plugin and platform requirement with the current Cordova documentation. Build and test one platform at a time; review permissions and network access rather than assuming that the old configuration transfers unchanged.

iOS and platform requirements

Creating a project and previewing web assets is different from compiling its native iOS application. A local iOS build needs the appropriate Apple development toolchain and signing configuration. Read the historical iOS guide for the old workflow, or the current Cordova iOS documentation for maintained development.

Sources & archive notes

Recovered repository material is attributed to its original authors and distributed with its source license. Changes: FreeSoft layout, archive context, navigation, link and image locations. Apache License 2.0 · Notices and provenance. Editorial material is labeled separately.