The Command-Line Interface

这篇指南介绍了如何使用命令行界面(CLI)创建应用程序并将其部署到多个原生移动平台。CLI允许您创建新项目、在不同平台上构建它们,并在真实设备或模拟器上运行。该工具是跨平台工作流程的主要工具,适用于不同平台的SDK和壳工具的初始化项目代码,然后进行持续开发。
摘要由CSDN通过智能技术生成

This guide shows you how to create applications and deploy them tovarious native mobile platforms using the cordova command-lineinterface (CLI). This tool allows you to create new projects, buildthem on different platforms, and run on real devices or withinemulators. The CLI is the main tool to use for the cross-platformworkflow described in the Overview. Otherwise you can also use theCLI to initialize project code, then switch to various platforms' SDKsand shell tools for continued development.

Prerequisites

Before running any command-line tools, you need to install SDKs foreach platform you wish to target.(See the Platform Guides for more details.)

To add support or rebuild a project for any platform, you need to runthe command-line interface from the same machine that supports theplatform's SDK. The CLI supports the following combinations:

  • iOS (Mac)
  • Amazon Fire OS (Mac, Linux, Windows)
  • Android (Mac, Linux, Windows)
  • BlackBerry 10 (Mac, Linux, Windows)
  • Windows Phone 7 (Windows)
  • Windows Phone 8 (Windows)
  • Windows 8 (Windows)
  • Firefox OS (Mac, Linux, Windows)

On the Mac, the command-line is available via the Terminalapplication. On the PC, it's available as Command Prompt underAccessories.

NOTE: For Windows-only platforms, you can still do yourdevelopment on Mac hardware by running Windows in a virtual machineenvironment or in dual-boot mode. For available options, see theWindows Phone Platform Guide or the Windows 8 Platform Guide.

The more likely it is that you run the CLI from different machines,the more it makes sense to maintain a remote source code repository,whose assets you pull down to local working directories.

Installing the Cordova CLI

The Cordova command-line tool is distributed as an npm package in aready-to-use format. It is not necessary to compile it from source.

To install the cordova command-line tool, follow these steps:

  1. Download and install Node.js. Followinginstallation, you should be able to invoke node and npm on yourcommand line. If desired, you may optionally use a tool such as nvm or nave to manage your Node.js installation.

  2. Download and install a git client, if you don'talready have one. Following installation, you should be able to invoke giton your command line. Even though you won't be using git manually,the CLI does use it behind-the-scenes to download some assets whencreating a new project.

  3. Install the cordova module using npm utility of Node.js. The cordovamodule will automatically be downloaded by the npm utility.

    • on OS X and Linux:

      $ sudo npm install -g cordova
      

      On OS X and Linux, prefixing the npm command withsudo may be necessary to install this development utility inotherwise restricted directories such as /usr/local/share. If you are using the optionalnvm/nave tool or have write access to the install directory,you may be able to omit the sudo prefix. There aremore tipsavailable on using npm without sudo, if you desire to do that.

    • on Windows:

      C:\>npm install -g cordova
      

    The -g flag above tells npm to install cordova globally. Otherwiseit will be installed in the node_modules subdirectory of the currentworking directory.

    You may need to add the npm directory to your PATH in order to invokeglobally installed npm modules. On Windows, npm can usually be found atC:\Users\username\AppData\Roaming\npm. On OS X and Linux it can usuallybe found at /usr/local/share/npm.

    The installation log may produce errors for any uninstalledplatform SDKs.

    Following installation, you should be able to runcordova on the command line with no arguments and it shouldprint help text.

Create the App

Go to the directory where you maintain your source code, and run acommand such as the following:

    $ cordova create hello com.example.hello HelloWorld

It may take some time for the command to complete, so be patient. Runningthe command with the -d option displays information about its progress.

The first argument hello specifies a directory to be generatedfor your project. This directory should not already exist, Cordova willcreate it for you. Its www subdirectory houses your application'shome page, along with various resources under css, js, and img,which follow common web development file-naming conventions. Theconfig.xml file contains important metadata needed to generate anddistribute the application.

The second argument com.example.helloprovides your project with a reverse domain-style identifier. This argumentis optional, but only if you also omit the third argument, since the argumentsare positional. You can editthis value later in the config.xml file, but do be aware that there maybe code generated outside of config.x

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值