Install, configure, and use phonegap 3 + [Figure]

Source: Internet
Author: User
Tags install node

If you reprint this article, enter the blog address and original author (risingwonderland ).


Phonegap2 + has a maximum version of 2.9.1. Starting from Version 3 +, phonegap does not officially provide the download installation package. You need to download and install the package through the node. js tool when it is online. The official installation instructions provide a simplified model:


Direct operations may be unclear in many places. This article provides the basic installation, configuration, and usage methods and precautions for the 3 + version.

Download and install ant

Ant is a Java-based packaging tool for installing 3 + versions of phonegap. This tool is available for download on the Apache official website.

How to install Windows:

1. Download ant from Apache.

2. Extract ant to a directory on the hard disk, such as the C root directory:


3. Add the path of the ant. BAT file in the bin folder to the System Path Environment Variable ("C: \ ant \ bin ").

Download and install node. js

Node. JS is required to install phonegap of version 3 +. After downloading and installing the tool on the official website, open the command line, run the NPM command to view the output result, or run the node command to enter the node command line mode. If the installation is successful, confirm that the installation is successful.

Download and install phonegap

Open the command line and enter "NPM install-G phonegap" to download and install the latest version of phonegap:


Because the download has been successful before, the HTTP status code in is 304, meaning that the version provided by the server is no different from the content of the current installed version, and no new content is returned.

For the first installation, the HTTP status code is 200.

After the phonegap is successfully installed, restart the command line tool and run the "phonegap" command to obtain the output result (Part 1 ):


If the command "phonegap" returns "not an internal or external command", close the command line, attempt to close or restart the program that may affect the operation, or restart the computer.

Under the "node_modules" folder on disk C, you will see the "phonegap" folder. Here is the downloaded phonegap file.

Configuration

To use phonegap to create and run Android programs, some configuration is required.

Install and configure jdk1.6 +.

Install the android environment of eclipse and eclipse.

Upgrade Android SDK to the latest version.

Add the andropid SDK information for the system path environment variable. Assume that the androidsdk folder is located in the root directory of the D Drive. Add "D: \ SDK \ tools" and "D: \ SDK \ platform-Tools" to the path environment variable.

Add the android plug-in information of eclipse to the System Path Environment Variable. Assume that the eclipse software with the android environment variable is located in the root directory of the D Drive, set "D: \ eclipse \ plugins \ Org. apache. ant_1.8.2.v20120109-1030 \ bin "adds the PATH environment variable.

Use

Open the command line and switch the path to the directory where you want to create the phonegap application, such as the C root directory.

Run the "phonegapcreate hello" command to create a phonegap program named "hello" in the project folder. After successful creation, you can see the "hello" folder in the C root directory.

You can also use the more detailed command "phonegap create Hello COM. demo. hello hellogp creates a project folder named "hello" and a project package named "com. demo. hello, the phonegap program named "hellogp.


Currently, the android program is not actually created, but the information is written into the config. xml file.


Run the "cdhello" command to switch to the "hello" directory.

Then, run different commands to perform the specified operation:

The "phonegapbuild android" command is used to create an android project. After the android project is created, you can view the android project file in the "C: \ Hello \ platforms" folder;

The "phonegapinstall android" command is used to run a project on an Android device;

The "phonegap-e install android" command is used to run a project on an android virtual device;

The "phonegaprun android" command is used to create an android project and run the project on the Android device in one step;

The "phoengap-e run Android" command is used to create an android project and run the project on the android virtual device in one step.

After running the command, compile and run the android program. If the current computer is not connected to an Android device for testing, phonegap will try to run the android Virtual Device (AVD ). If you have not created an android virtual device before, the command line will prompt that the program is terminated:


If the current computer is connected to an Android device for testing, the android program we created can be installed and tested using this device:


The basic phonegap application runs on the mobile phone:


Import eclipse

To facilitate development, we need to import the android project into eclipse. Some problems may occur during the import process.

After selecting the android project in the project file during the import process, you will encounter this step:


The project file contains two projects. The above project is the hellogp program we created, and the following project is the class library file provided by phonegap, which is equivalent to Cordova. jar earlier than 3 +. We want to edit the above program, but both projects must be imported, and the "Copy projects into workspace" option cannot be checked. Otherwise, a missing class file error occurs. Therefore, do not create a project in a temporary work interval for ease of management.

After the project is imported, the project is different from the version 3 +. Assets are not in the WWW folder, and the config. xml file is not in the "Res/XML" directory. The parameters received in the super. loadurl method in the activity are not directly HTML address strings.

 

More information

Command to update phonegap to the latest version: NPM Update-G phonegap

Command for viewing phonegap version information: phonegap version or phonegap-V

Command for viewing phonegap details: NPM info phonegap


Command for installing the specified phonegap version: NPM install-G [email protected] [specific version]

Notes

Sometimes the android project fails to be compiled through the command line, and a prompt indicating that the build-Tools version is too low is displayed. Open SDK manager to ensure that the current version has been updated to the latest version.

If you fail to download phonegap after confirming that the configuration is correct, try again several times. If it still fails, consider enabling the scientific Internet access mode.


If you reprint this article, enter the blog address and original author (risingwonderland ).



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.