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

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.

主站蜘蛛池模板: 华亭县| 左贡县| 韩城市| 汽车| 财经| 温州市| 阜宁县| 雷州市| 阜宁县| 兴仁县| 观塘区| 湘乡市| 青冈县| 资中县| 西林县| 乌鲁木齐县| 大足县| 赤壁市| 蓝田县| 镇赉县| 弋阳县| 蓬溪县| 资中县| 安福县| 武胜县| 昌乐县| 海宁市| 阿巴嘎旗| 铁力市| 兰坪| 巨鹿县| 天镇县| 郸城县| 五河县| 宁安市| 长宁县| 罗源县| 原平市| 恭城| 清新县| 苏州市|