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

Creating a new project

Creating a new PhoneGap project is easy thanks to PhoneGap CLI. Unlike older versions of PhoneGap, where we needed to download the project template manually, we can create new projects directly from the command line. With just a single command, we can create a new project and start writing our application.

How to do it…

To create a new PhoneGap project, open your terminal or cmd. Then go to the directory where you want to maintain your source code. Run the following command:

phonegap create hello com.myapp.hello HelloWorld

It may take some time to complete the process, so be patient and let PhoneGap CLI do its magic. You will see some message during the project creation process:

How to do it…

Creating a new project progress

Congratulations! You have created your first PhoneGap project. Now, let's browse the project directory. You will see the directories as shown in the following screenshot:

How to do it…

The PhoneGap project structure

Most of the directories are empty; we will discuss the use of each directory later in the next recipe. The www/ directory is where you write code for your application. PhoneGap generated the initial starter app to work with.

How it works…

The phonegap create command is a command used to create a new project. The first argument, hello, specifies a directory for your project. Note that this directory must not exist initially; phonegap will create it for you.

The second argument, com.myapp.hello, is your application ID. The application ID is used as a unique identifier for an application. Two identical applications with different application IDs will be considered two different applications. The application ID is in reverse domain style. You can create something like com.yourdomain.applicationname.

The third argument, HelloWorld, is your application name. The application name will be used as the application's display title. This argument is optional. If you are not setting the application name, it will use the name from the first argument. If you want to change the name, you can open config.xml and edit the name element.

While we are running the phonegap create command, there are several things happening in the background:

  • The phonegap creates a new PhoneGap project with the given name and ID in the newly created directory. In our case, a PhoneGap project with the name as HelloWorld and ID as com.myapp.hello will be created under the hello directory.
  • The phonegap downloads the starter application and places it in www/ so that we can run the project directly after creating it.

    Tip

    You can use the -d option with any phonegap command to allow a verbose output. The -d option will give clear information about what is going on and the current status of the command.

主站蜘蛛池模板: 萨嘎县| 凤阳县| 杭锦旗| 牟定县| 黄陵县| 寻甸| 河津市| 龙口市| 舒城县| 深州市| 万源市| 旌德县| 凌源市| 桂林市| 新郑市| 乐都县| 宣化县| 吉安市| 麻江县| 四子王旗| 甘洛县| 武川县| 克东县| 洪湖市| 久治县| 静宁县| 澳门| 留坝县| 柯坪县| 盐城市| 柳江县| 内江市| 怀宁县| 马公市| 沂源县| 佛教| 郯城县| 西乌珠穆沁旗| 孙吴县| 班玛县| 太仆寺旗|