Installing PhoneGap in Windows
Do you want to migrate from PhoneGap V2.9 or below to V3.0 or above? or
Do you want to try the latest PhoneGap 3.5 Command Line tools or Do you
just want to start learning PhoneGap?. This article will help you to do
it by completing the first step towards PhoneGap V3.X, which is
installing PhoneGap on Windows Machine as the process includes
installation of many required libraries which are not mentioned in the
PhoneGap Website.
Follow these steps to Install PhoneGap in Windows
- Install Node
- Install JDK (JDK V7 for Win7, and JDK V8 for Win8)
- Install Git
- Install Ant
- Setup Environment Variables :
New system variable "JAVA_HOME" to <path to Java sdk folder>
New system variable "ANT_HOME" to <path to ant folder>
Add to existing system variable "path" : %JAVA_HOME%\bin;%ANT_HOME%\bin
- Install PhoneGap from Command prompt:
npm install -g phonegap
If you get any error starting with "npm ERR! Error: ENOENT", open cmd prompt with administrator rights.
For Android Development:
- Install Eclipse ADT (Note : for win8 32bit/64bit install 32bit ADT)
- Setup Environment Variables :
Add to existing system variable "path" : <path to adt-bundle\sdk\tools>;<path to adt-bundle\sdk\platform-tools>
For Windows 8 Development:
- Windows OS 8 Machine is required
- Install Windows Phone SDK 8.0
For Windows 8.1 Development :
- Windows OS 8.1 Machine is required
- Install Microsoft Visual Studio Express 2013 with Update 2 for Windows
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.
know more about the CLI commands and their usage.
At this point, to create a new project you can choose between the
cross-platform CLI tool described in
The Command-Line Interface, or
the set of Android-specific shell tools. From within a source-code
directory, here's the CLI approach:
$ cordova create hello com.example.hello HelloWorld
$ cd hello
$ cordova platform add android
$ cordova build
Here's the corresponding lower-level shell-tool approach for both Unix
and Windows:
$ /path/to/cordova-android/bin/create /path/to/new/hello com.example.hello HelloWorld
C:\path\to\cordova-android\bin\create.bat C:\path\to\new\hello com.example.hello HelloWorld
Here's how to use the SDK to modify it:
- Launch the Eclipse application.
- Select the New Project menu item.
-
Choose Android Project from Existing Code from the resulting
dialog box, and press Next:

- If you're using the CLI, navigate to the
hello directory you
created for the project, then to the platforms/android
subdirectory. Alternately, if you use the create shell utility,
simply navigate to the hello directory.
- Press Finish.
Once the Eclipse window opens, a red
X may appear to indicate
unresolved problems. If so, follow these additional steps:
- Right-click on the project directory.
- In the resulting Properties dialog, select Android from the navigation pane.
- For the project build target, select the highest Android API level you have installed.
- Click OK.
- Select Clean from the Project menu. This should correct all the errors in the project.
If you are using the CLI in development, the project directory's
top-level
www directory contains the source files. Run either of
these within the project directory to rebuild the app:
$ cordova build
$ cordova build android # do not rebuild other platforms
If you are using the Android-specific shell tools in development,
there is a different approach. Once you generate the project, the
default app's source is available in the
assets/www subdirectory.
Subsequent commands are available in its
cordova subdirectory.
The
build command cleans project files and rebuilds the app. Here is
the syntax for both Mac and Windows. The first pair of examples
generate debugging information, and the second signs the apps for
release:
$ /path/to/project/cordova/build --debug
C:\path\to\project\cordova\build.bat --debug
$ /path/to/project/cordova/build --release
C:\path\to\project\cordova\build.bat --release
You can use either the
cordova CLI utility or Cordova's
Android-centered shell tools to run an app in an emulator. Either
way, the SDK must first be configured to display at least one device.
To do so, use the Android SDK Manager, a Java application that runs
separately from Eclipse. There are two ways to open it:
- Run
android on the command line.
-
From within Eclipse, press this toolbar icon:

Once open, the Android SDK Manager displays various runtime libraries:

Choose
Tools → Manage AVDs (Android Virtual Devices), then
choose any item from
Device Definitions in the resulting dialog
box:

Press
Create AVD, optionally modifying the name, then press
OK
to accept the changes:

The AVD then appears in the
Android Virtual Devices list:

To open the emulator as a separate application, select the AVD and
press
Start. It launches much as it would on the device, with
additional controls available for hardware buttons:
At this point you can use the
cordova CLI utility to deploy the
application to the emulator from the command line:
$ cordova emulate android
Otherwise use the alternate shell interface:
$ /path/to/project/cordova/run --emulator
Instead of relying on whichever emulator is currently enabled within
the SDK, you can refer to each by the names you supply:
$ /path/to/project/cordova/run --target=NAME
This pushes the app to the home screen and launches it:

When you
run the app, you also
build it. You can append additional
--debug,
--release, and
--nobuild flags to control how it is
built, or even whether a rebuild is necessary:
$ /path/to/project/cordova/run --emulator --nobuild
If instead you are working within Eclipse, right-click the project and
choose
Run As → Android Application. You may be asked to
specify an AVD if none are already open.
For a faster experience, you can use the
Virtual Machine Acceleration to improve
the execution speed.
Many modern CPUs provide extensions to execute Virtual Machines more efficiently.
Before attempting to use this type of acceleration, you need to determine if your
current development system's CPU, supports one the following virtualization technologies:
-
Intel Virtualization Technology (VT-x, vmx) → Intel VT-x supported processor list
-
AMD Virtualization (AMD-V, SVM), only supported for Linux (Since May 2006, all CPUs AMD include AMD-V, except Sempron).
Another way to find out if your Intel processor supports VT-x Technology, it's by executing the
Intel Processor Identification Utility, for
Windowsyou can download it from the Intel
Download Center,
or you can use the
booteable utility, which is
OS Independent.
After install and execute the
Intel Processor Identification Utility over Windows, you will get the following window,
in order to check if your CPU supports the Virtualization Technologies:

In order to speed up the emulator, you need to download and install one or more
Intel x86 Atom System Images,
as well as the
Intel Hardware Accelerated Execution Manager (HAXM).
Open your Android SDK Manager, and select the
Intel x86 Atom System Image, for whichever version that you want to test. Then go to
Extras
and select
Intel x86 Emulator Accelerator (HAXM), and install those packages:

After download, run the Intel installer, which is available within your
Android SDK at
extras/intel/Hardware_Accelerated_Execution_Manager.
Note:
If you have any problems installing the package, you can find more information and step by step guidance check this
Intel Article.
- Install one or more
Intel x86 Atom System Images as well as the
Intel Hardware Accelerated Execution Manager, available under
Extras.
- Run the Intel installer, which is available within your Android SDK
at
extras/intel/Hardware_Accelerated_Execution_Manager.
- Create a new AVD with the target set to an Intel image.
- When starting the emulator, ensure there are no error messages
indicating a failure to load HAX modules.
To push an app directly to the device, make sure USB debugging is
enabled on your device as described on the
Android Developer Site,
and use a mini USB cable to plug it into your system.
You can use this CLI command to push the app to the device:
$ cordova run android
...or use this Android-centered shell interface:
$ /path/to/project/cordova/run --device
With no flags specified, the
run command detects a connected
device, or a currently running emulator if no device is found,
otherwise it prompts to specify an emulator.
To run the app from within Eclipse, right-click the project and choose
Run As → Android Application.
The following generates a detailed log of the app as it runs:
$ /path/to/project/cordova/log
C:\path\to\project\cordova\log.bat
The following cleans the project files:
$ /path/to/project/cordova/clean
C:\path\to\project\cordova\clean.bat