UNPKG

17.5 kBMarkdownView Raw
1<!--
2#
3# Licensed to the Apache Software Foundation (ASF) under one
4# or more contributor license agreements. See the NOTICE file
5# distributed with this work for additional information
6# regarding copyright ownership. The ASF licenses this file
7# to you under the Apache License, Version 2.0 (the
8# "License"); you may not use this file except in compliance
9# with the License. You may obtain a copy of the License at
10#
11# http://www.apache.org/licenses/LICENSE-2.0
12#
13# Unless required by applicable law or agreed to in writing,
14# software distributed under the License is distributed on an
15# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16# KIND, either express or implied. See the License for the
17# specific language governing permissions and limitations
18# under the License.
19#
20-->
21
22# cordova-cli
23
24> The command line tool to build, deploy and manage [Cordova](http://cordova.io)-based applications.
25
26[Apache Cordova](http://cordova.io) allows for building native mobile applications using HTML, CSS and JavaScript. This tool helps with management of multi-platform Cordova applications as well as Cordova plugin integration.
27
28Check out the [Getting Started guides](http://cordova.apache.org/docs/en/edge/) for more details on how to work with Cordova sub-projects.
29
30# Supported Cordova Platforms
31
32- Amazon Fire OS
33- Android
34- BlackBerry 10
35- iOS
36- Ubuntu
37- Windows Phone 8
38- Windows 8
39
40# Requirements
41
42* [Node.js](http://nodejs.org/)
43* SDKs for each platform you wish to support:
44 - **Android**: [Android SDK](http://developer.android.com) - **NOTE** This tool
45 will not work unless you have the absolute latest updates for all
46 Android SDK components. Also you will need the SDK's `tools` and `platform-tools` directories on your __system path__ otherwise Android support will fail.
47 - **amazon-fireos**: [Amazon Fire OS SDK](https://developer.amazon.com/public/solutions/platforms/android-fireos/docs/building-and-testing-your-hybrid-app) - **NOTE** This tool will not work unless you have Android SDK installed and paths are updated as mentioned above. In addition you need to install AmazonWebView SDK and copy awv_interface.jar on **Mac/Linux** system to ~/.cordova/lib/commonlibs folder or on **Windows** %USERPROFILE%/.cordova/lib/coomonlibs. If commonlibs folder does not exist then create one.
48 - [Windows Phone SDK](http://dev.windowsphone.com/en-us/downloadsdk) - **NOTE** This tool will not work unless you have `msbuild` on your __system path__ otherwise Windows Phone support will fail (`msbuild.exe` is generally located in `C:\Windows\Microsoft.NET\Framework\v4.0.30319`).
49 - **BlackBerry 10**: [BlackBerry 10 WebWorks SDK](http://developer.blackberry.com/html5/download/). Make sure you have the `dependencies/tools/bin` folder inside the SDK directory added to your path!
50 - **iOS**: [iOS SDK](http://developer.apple.com) with the latest `Xcode` and `Xcode Command Line Tools`
51 - **Windows Phone**: [Windows Phone SDK](http://dev.windowsphone.com/en-us/downloadsdk) - **NOTE** This tool will not work unless you have `msbuild` on your __system path__ otherwise Windows Phone support will fail (`msbuild.exe` is generally located in `C:\Windows\Microsoft.NET\Framework\v4.0.30319`).
52
53`cordova-cli` has been tested on **Mac OS X**, **Linux**, **Windows 7**, and **Windows 8**.
54
55Please note that some platforms have OS restrictions. For example, you cannot build for Windows 8 or Windows Phone 8 on Mac OS X, nor can you build for iOS on Windows.
56
57# Install
58
59Ubuntu packages are available in a PPA for Ubuntu 13.10 (Saucy) (the current release) as well as 14.04 (Trusty) (under development).
60
61 sudo apt-add-repository ppa:cordova-ubuntu/ppa
62 sudo apt-get update
63 sudo apt-get install cordova-cli
64 npm install -g cordova
65
66To build an application for the Ubuntu platform, the following extra packages are required:
67
68 sudo apt-get install cmake debhelper libx11-dev libicu-dev pkg-config qtbase5-dev qtchooser qtdeclarative5-dev qtfeedback5-dev qtlocation5-dev qtmultimedia5-dev qtpim5-dev qtsensors5-dev qtsystems5-dev
69
70
71## Installing from master
72
73You'll need to install both [CLI](https://git-wip-us.apache.org/repos/asf/cordova-cli.git) and [Plugman](https://git-wip-us.apache.org/repos/asf/cordova-plugman.git) from `git`. Running the *npm version* of one and *(git) master version* of the other is likely to end with you suffering.
74
75To avoid using sudo, see [Get away from sudo: npm without root](http://justjs.com/posts/npm-link-developing-your-own-npm-modules-without-tears).
76
77Run the following commands:
78
79 git clone https://git-wip-us.apache.org/repos/asf/cordova-plugman.git
80 cd cordova-plugman
81 npm install
82 sudo npm link
83 cd ..
84 git clone https://git-wip-us.apache.org/repos/asf/cordova-cli.git
85 cd cordova-cli
86 npm install
87 sudo npm link
88 npm link plugman
89
90Now the `cordova` and `plugman` in your path are the local git versions. Don't forget to keep them up to date!
91
92## Installing on Ubuntu
93
94 apt-get install cordova-cli
95
96
97# Getting Started
98
99`cordova-cli` has a single global `create` command that creates new Cordova projects into a specified directory. Once you create a project, `cd` into it and you can execute a variety of project-level commands. Completely inspired by git's interface.
100
101## Global Commands
102
103- `help` display a help page with all available commands
104- `create <directory> [<id> [<name>]]` create a new Cordova project with optional name and id (package name, reverse-domain style)
105
106<a name="project_commands" />
107## Project Commands
108
109- `platform [ls | list]` list all platforms for which the project will build
110- `platform add <platform> [<platform> ...]` add one (or more) platforms as a build target for the project
111- `platform [rm | remove] <platform> [<platform> ...]` removes one (or more) platform build targets from the project
112- `platform [up | update] <platform> ` - updates the Cordova version used for the given platform
113- `plugin [ls | list]` list all plugins included in the project
114- `plugin add <path-to-plugin> [<path-to-plugin> ...]` add one (or more) plugins to the project
115- `plugin [rm | remove] <plugin-name> [<plugin-name> ...]` remove one (or more) plugins from the project.
116- `plugin search [<keyword1> <keyword2> ...]` search the plugin registry for plugins matching the list of keywords
117- `prepare [platform...]` copies files into the specified platforms, or all platforms. It is then ready for building by `Eclipse`, `Xcode`, etc.
118- `compile [platform...]` compiles the app into a binary for each targetted platform. With no parameters, builds for all platforms, otherwise builds for the specified platforms.
119- `build [<platform> [<platform> [...]]]` an alias for `cordova prepare` followed by `cordova compile`
120- `emulate [<platform> [<platform> [...]]]` launch emulators and deploy app to them. With no parameters emulates for all platforms added to the project, otherwise emulates for the specified platforms
121- `serve [port]` launch a local web server allowing you to access each platform's www directory on the given port (default 8000).
122
123### Optional Flags
124
125- `-d` or `--verbose` will pipe out more verbose output to your shell. You can also subscribe to `log` and `warn` events if you are consuming `cordova-cli` as a node module by calling `cordova.on('log', function() {})` or `cordova.on('warn', function() {})`.
126- `-v` or `--version` will print out the version of your `cordova-cli` install.
127
128# Project Directory Structure
129A Cordova application built with `cordova-cli` will have the following directory structure:
130
131 myApp/
132 |-- config.xml
133 |-- hooks/
134 |-- merges/
135 | | |-- android/
136 | | |-- blackberry10/
137 | | `-- ios/
138 |-- www/
139 |-- platforms/
140 | |-- android/
141 | |-- blackberry10/
142 | `-- ios/
143 `-- plugins/
144
145## hooks/
146This directory may contains scripts used to customize cordova-cli commands. This
147directory used to exist at `.cordova/hooks`, but has now been moved to the
148project root. Any scripts you add to these directories will be executed before
149and after the commands corresponding to the directory name. Useful for
150integrating your own build systems or integrating with version control systems.
151
152Refer to [hooks-README.md](https://github.com/apache/cordova-lib/blob/master/cordova-lib/templates/hooks-README.md) for more information.
153
154## merges/
155Platform-specific web assets (HTML, CSS and JavaScript files) are contained within appropriate subfolders in this directory. These are deployed during a `prepare` to the appropriate native directory. Files placed under `merges/` will override matching files in the `www/` folder for the relevant platform. A quick example, assuming a project structure of:
156
157 merges/
158 |-- ios/
159 | `-- app.js
160 |-- android/
161 | `-- android.js
162 www/
163 `-- app.js
164
165After building the Android and iOS projects, the Android application will contain both `app.js` and `android.js`. However, the iOS application will only contain an `app.js`, and it will be the one from `merges/ios/app.js`, overriding the "common" `app.js` located inside `www/`.
166
167## www/
168
169Contains the project's web artifacts, such as .html, .css and .js files. These are your main application assets. They will be copied on a `cordova prepare` to each platform's www directory.
170
171### Your Blanket: config.xml
172
173This file is what you should be editing to modify your application's metadata. Any time you run any cordova-cli commands, the tool will look at the contents of `config.xml` and use all relevant info from this file to define native application information. cordova-cli supports changing your application's data via the following elements inside the `config.xml` file:
174
175- The user-facing name can be modified via the contents of the `<name>` element.
176- The package name (AKA bundle identifier or application id) can be modified via the `id` attribute from the top-level `<widget>` element.
177- The version can be modified via the `version` attribute from the top-level `<widget>` element.
178- The whitelist can be modified using the `<access>` elements. Make sure the `origin` attribute of your `<access>` element points to a valid URL (you can use `*` as wildcard). For more information on the whitelisting syntax, see the [docs.phonegap.com](http://docs.phonegap.com/en/2.2.0/guide_whitelist_index.md.html#Domain%20Whitelist%20Guide). You can use either attribute `uri` ([BlackBerry-proprietary](https://developer.blackberry.com/html5/documentation/access_element_834677_11.html)) or `origin` ([standards-compliant](http://www.w3.org/TR/widgets-access/#attributes)) to denote the domain.
179- Platform-specific preferences can be customized via `<preference>` tags. See [docs.phonegap.com](http://docs.phonegap.com/en/2.3.0/guide_project-settings_index.md.html#Project%20Settings) for a list of preferences you can use.
180- The entry/start page for your application can be defined via the `<content src>` element + attribute.
181
182## platforms/
183Platforms added to your application will have the native application project structures laid out within this directory.
184
185## plugins/
186Any added plugins will be extracted or copied into this directory.
187
188# Hooks
189
190Projects created by cordova-cli have `before` and `after` hooks for each [project command](#project_commands).
191
192There are two types of hooks: project-specific ones and module-level ones. Both of these types of hooks receive the project root folder as a parameter.
193
194## Project-specific Hooks
195
196These are located under the `hooks` directory in the root of your Cordova project. Any scripts you add to these directories will be executed before and after the appropriate commands. Useful for integrating your own build systems or integrating with version control systems. __Remember__: make your scripts executable.
197
198### Examples
199
200- [`before_build` hook for jade template compiling](https://gist.github.com/4100866) courtesy of [dpogue](http://github.com/dpogue)
201
202## Module-level Hooks
203
204If you are using cordova-cli as a module within a larger **Node** application, you can also use the standard `EventEmitter` methods to attach to the events. The events include `before_build`, `before_compile`, `before_docs`, `before_emulate`, `before_run`, `before_platform_add`, `before_library_download`, `before_platform_ls`, `before_platform_rm`, `before_plugin_add`, `before_plugin_ls`, `before_plugin_rm` and `before_prepare`. There is also a `library_download` progress event. Additionally, there are `after_` flavours of all the above events.
205
206Once you `require('cordova')` in your Node project, you will have the usual `EventEmitter` methods available (`on`, `off` or `removeListener`, `removeAllListeners`, and `emit` or `trigger`).
207
208# Examples
209
210## Creating a new Cordova project
211This example shows how to create a project from scratch named KewlApp with iOS and Android platform support, and includes a plugin named Kewlio. The project will live in ~/KewlApp
212
213 cordova create ~/KewlApp KewlApp
214 cd ~/KewlApp
215 cordova platform add ios android
216 cordova plugin add http://example.org/Kewlio-1.2.3.tar.gz
217 cordova build
218
219The directory structure of KewlApp now looks like this:
220
221 KewlApp/
222 |-- hooks/
223 |-- merges/
224 | |-- android/
225 | `-- ios/
226 |-- www/
227 | `-- index.html
228 |-- platforms/
229 | |-- android/
230 | | `-- …
231 | `-- ios/
232 | `-- …
233 `-- plugins/
234 `-- Kewlio/
235
236# Contributing
237
238## Running Tests
239
240 npm test
241
242## Get test coverage reports
243
244 npm run cover
245
246## TO-DO + Issues
247
248Please check [Cordova issues with the CLI Component](http://issues.cordova.io). If you find issues with this tool, please be so kind as to include relevant information needed to debug issues such as:
249
250- Your operating system and version
251- The application name, directory location, and identifier used with `create`
252- Which mobile SDKs you have installed, and their versions. Related to this: which `Xcode` version if you are submitting issues related to iOS
253- Any error stack traces you received
254
255## Contributors
256
257Thanks to everyone for contributing! For a list of people involved, please see the `package.json` file.
258
259
260# Known Issues and Troubleshooting
261
262## Any OS
263
264### Proxy Settings
265
266`cordova-cli` will use `npm`'s proxy settings. If you downloaded cordova-cli via `npm` and are behind a proxy, chances are cordova-cli should work for you as it will use those settings in the first place. Make sure that the `https-proxy` and `proxy` npm config variables are set properly. See [npm's configuration documentation](https://npmjs.org/doc/config.html) for more information.
267
268## Windows
269
270### Trouble Adding Android as a Platform
271
272When trying to add a platform on a Windows machine if you run into the following error message:
273 Cordova library for "android" already exists. No need to download. Continuing.
274 Checking if platform "android" passes minimum requirements...
275 Checking Android requirements...
276 Running "android list target" (output to follow)
277
278 Error: The command `android` failed. Make sure you have the latest Android SDK installed, and the `android` command (inside the tools/ folder) added t
279 o your path. Output:
280 at C:\Users\me\AppData\Roaming\npm\node_modules\cordova\src\platform.js:185:42
281 at C:\Users\me\AppData\Roaming\npm\node_modules\cordova\src\metadata\android_parser.js:50:13
282 at C:\Users\me\AppData\Roaming\npm\node_modules\cordova\node_modules\shelljs\shell.js:1707:7
283 at exithandler (child_process.js:633:7)
284 at ChildProcess.errorhandler (child_process.js:649:5)
285 at ChildProcess.EventEmitter.emit (events.js:95:17)
286 at Process.ChildProcess._handle.onexit (child_process.js:787:12)
287
288run the command `android list target`. If you see:
289
290 'xcopy' is not recognized as an internal or external command,
291 operable program or batch file.
292
293at the beginning of the command output, it means you will need to fix your Windows Path variable to include xcopy. This location is typically under C:\Windows\System32.
294
295## Windows 8
296
297Windows 8 support does not include the ability to launch/run/emulate, so you will need to open **Visual Studio** to see your app live. You are still able to use the following commands with windows8:
298
299- `platform add windows8`
300- `platform remove windows8`
301- `prepare windows8`
302- `compile windows8`
303- `build windows8`
304
305To run your app, you will need to open the `.sln` in the `platforms/windows8` folder using **Visual Studio 2012**.
306
307**Visual Studio** will tell you to reload the project if you run any of the above commands while the project is loaded.
308
309## Amazon Fire OS
310
311Amazon Fire OS does not include the ability to emulate. You are still able to use the following commands with Amazon Fire OS
312
313- `platform add amazon-fireos`
314- `platform remove amazon-fireos`
315- `prepare amazon-fireos`
316- `compile amazon-fireos`
317- `build amazon-fireos`
318
319## Ubuntu
320
321The initial release of cordova-ubuntu does not support building applications for armhf devices automatically. It is possible to produce applications and click packages in a few steps though.
322
323This bug report documents the issue and solutions for it: https://bugs.launchpad.net/ubuntu/+source/cordova-ubuntu/+bug/1260500 A future release will let developers cross-compile armhf click packages directly from an x86 desktop.
324
325## Firefox OS
326
327Firefox OS does not include the ability to emulate, run and serve. After building, you will have to open the firefoxos platform directory of your app in the App Manager that comes with every firefox browser.