官术网_书友最值得收藏!

Time for action – setting up Android using PhoneGap 3.x

Get ready to set up the Android development environment and create a PhoneGap app using Android as the target platform. In the previous section, we saw how to create a new project. Now it's time to add the desired platform to the project. As usual, use Terminal on OS X or DOS Prompt on Windows to run these commands.

  1. Launch a command-line tool (DOS or Terminal) and change the directory to the directory where we just downloaded the Cordova/PhoneGap distribution, as shown here:
    $ cd hello
    
  2. In order to create a PhoneGap project for Android, all you have to do is run the command to add a platform to the project:
    $ phonegap platform add android
    

The command tells Cordova to add support for the Android platform. After the successful execution of the command, you can see a new directory named android created inside the platform directory. This contains all the platform-dependent files.

Now it's time to run the project in the emulator. The following command will take some time to complete:

$ phonegap emulate android

The tool will check whether some virtual devices are already defined and prompt the user to define one if not. If there is more than one device already defined, the tool will ask which one to use.

What just happened?

You created a PhoneGap project and emulated the app in one of the testing devices configured within your Android SDK.

Working with other platforms

To work with different platforms such as iOS, Windows Phone, and others, you have to follow the same process that we did for Android. The list of platforms that you can add to your project depends on the platform name. Before you add the platforms, you should ensure that you have the required SDKs installed on your machine.

On a Windows machine, you can run any of the following commands provided you have the required SDKs installed for each platform. You will not see the iOS platform here as we need a Mac machine to work on iOS:

C:\hello> phonegap platform add wp7
C:\hello> phonegap platform add wp8
C:\hello> phonegap platform add windows8
C:\hello> phonegap platform add amazon-fireos
C:\hello> phonegap platform add android
C:\hello> phonegap platform add blackberry10
C:\hello> phonegap platform add firefoxos

In the preceding commands, wp7 and wp8 denote Windows Phone 7 and 8, respectively.

On a Mac machine, you can develop on the following platforms after installing the corresponding platform SDKs. You will not see the Windows Phone platform here as we need the Windows operating system to install the Windows Phone SDK:

$ phonegap platform add ios
$ phonegap platform add amazon-fireos
$ phonegap platform add android
$ phonegap platform add blackberry10
$ phonegap platform add firefoxos
主站蜘蛛池模板: 辽源市| 汽车| 谷城县| 彭州市| 甘肃省| 古丈县| 菏泽市| 克东县| 偏关县| 左贡县| 霍邱县| 阜城县| 花莲县| 永平县| 内黄县| 肥乡县| 资源县| 保德县| 崇仁县| 兰州市| 四子王旗| 咸丰县| 本溪| 呼玛县| 远安县| 凤冈县| 安新县| 庆安县| 常州市| 安吉县| 南平市| 鹤峰县| 星子县| 喀喇沁旗| 上杭县| 四子王旗| 河西区| 三明市| 大冶市| 武平县| 高邮市|