cordova配置安装

结合网上资料整理,分享~~~

一、系统环境配置

准备

首先你需要安装一些依赖包和配置环境。如果你的开发环境是Linux或Mac,需要把下面命令写在~/.bash_profile中,然后执行source ~/.bash_profile。如果是windows,则需要将这些变量添加到”我的电脑”->”环境变量”中。

JDK

下载地址:http://www.oracle.com/technetwork/java/javase/downloads/index.html

设置环境变量:

JAVA_HOME=/path/to/jdk

JAR_HOME=$JAVA_HOME/jre

PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH

CLASSPATH=$CLASSPATH:.:$JAVA_HOME/lib: :.:$JAVA_HOME/jre/lib

Apache Ant

下载地址:http://ant.apache.org

设置环境变量:

ANT_HOME=/path/to/ant

PATH=$ANT_HOME/bin/:$PATH

Android SDK

下载地址:http://developer.android.com/sdk/installing/index.html?pkg=adt

设置环境变量:

ANDROID_HOME=/path/to/sdk

PATH=$PATH:$ANDROID_HOME/platform-tools:$ANDROID_HOME/tools

Node.js

下载地址:http://nodejs.org/download/

二、Cordova环境配置

Installing the Cordova CLI

The Cordova command-line tool is distributed as an npm package.

To install thecordovacommand-line tool, follow these steps:

1Download and installNode.js. On installation you should be able to invokenodeandnpmon your command line.

2(Optional) Download and install agit client, if you don't already have one. Following installation, you should be able to invokegiton your command line. The CLI uses it to download assets when they are referenced using a url to a git repo.

3Install thecordovamodule usingnpmutility of Node.js. Thecordovamodule will automatically be downloaded by thenpmutility.

•on OS X and Linux:

$sudo npm install -g cordova

On OS X and Linux, prefixing thenpmcommand withsudomay be necessary to install this development utility in otherwise restricted directories such as/usr/local/share. If you are using the optional nvm/nave tool or have write access to the install directory, you may be able to omit thesudoprefix. There aremore tipsavailable on usingnpmwithoutsudo, if you desire to do that.


Create the App

Go to the directory where you maintain your source code, and create a cordova project:

$cordova create code com.example.code codeDemo

This creates the required directory structure for your cordova app. By default, thecordova createscript generates a skeletal web-based application whose home page is the project'swww/index.htmlfile.


Add Platforms

All subsequent commands need to be run within the project's directory, or any subdirectories:

$cdhello

Add the platforms that you want to target your app. We will add the 'ios' and 'android' platform and ensure they get saved toconfig.xml:

$cordova platform add ios --save

$cordova platform add android --save

To check your current set of platforms:

$cordova platform ls

Running commands to add or remove platforms affects the contents of the project'splatformsdirectory, where each specified platform appears as a subdirectory.

Install pre-requisites for building

To build and run apps, you need to install SDKs for each platform you wish to target. Alternatively, if you are using browser for development you can usebrowserplatform which does not require any platform SDKs.

To check if you satisfy requirements for building the platform:

$ cordova requirements

Requirements check results for android:

Java JDK: installed .

Android SDK: installed

Android target: installed android-19,android-21,android-22,android-23,Google Inc.:Google APIs:19,Google Inc.:Google APIs (x86 System Image):19,Google Inc.:Google APIs:23

Gradle: installed

Requirements check results for ios:

Apple OS X: not installed

Cordova tooling for iOS requires Apple OS X

Error: Some of requirements check failed


Build the App

By default,cordova createscript generates a skeletal web-based application whose start page is the project'swww/index.htmlfile. Any initialization should be specified as part of thedevicereadyevent handler defined inwww/js/index.js.

Run the following command to build the project forallplatforms:

$cordova build

You can optionally limit the scope of each build to specific platforms - 'ios' in this case:

$cordova build ios


Test the App

SDKs for mobile platforms often come bundled with emulators that execute a device image, so that you can launch the app from the home screen and see how it interacts with many platform features. Run a command such as the following to rebuild the app and view it within a specific platform's emulator:

$cordova emulate android


Add Plugins

You can modify the default generated app to take advantage of standard web technologies, but for the app to access device-level features, you need to add plugins.

Apluginexposes a Javascript API for native SDK functionality. Plugins are typically hosted on npm and you can search for them on theplugin search page. Some key APIs are provided by the Apache Cordova open source project and these are referred to asCore Plugin APIs. You can also use the CLI to launch the search page:

$cordova plugin search camera

To add the camera plugin, we will specify the npm package name for the camera plugin:

$ cordova plugin add cordova-plugin-camera

Fetching plugin "cordova-plugin-camera@~2.1.0" via npm

Installing "cordova-plugin-camera" for android

Installing "cordova-plugin-camera" for ios

Plugins can also be added using a directory or a git repo.

NOTE: The CLI adds plugin code as appropriate for each platform. If you want to develop with lower-level shell tools or platform SDKs as discussed in theOverview, you need to run the Plugman utility to add plugins separately for each platform. (For more information, seeUsing Plugman to Manage Plugins.)

Useplugin ls(orplugin list, orpluginby itself) to view currently installed plugins. Each displays by its identifier:

$ cordova plugin ls

cordova-plugin-camera 2.1.0 "Camera"

cordova-plugin-whitelist 1.2.1 "Whitelist"


Updating Cordova and Your Project

After installing thecordovautility, you can always update it to the latest version by running the following command:

$sudo npm update -g cordova

Use this syntax to install a specific version:

$sudo npm install -g cordova@3.1.0-0.2.0

Runcordova -vto see which version is currently running. To find the latest released cordova version, you can run:

$npm info cordova version

To update platform that you're targeting:

$cordova platform update android --save

$cordova platform update ios --save

...etc.


最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 158,736评论 4 362
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,167评论 1 291
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 108,442评论 0 243
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 43,902评论 0 204
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,302评论 3 287
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,573评论 1 216
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,847评论 2 312
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,562评论 0 197
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,260评论 1 241
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,531评论 2 245
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,021评论 1 258
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,367评论 2 253
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,016评论 3 235
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,068评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,827评论 0 194
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,610评论 2 274
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,514评论 2 269

推荐阅读更多精彩内容

  • afinalAfinal是一个android的ioc,orm框架 https://github.com/yangf...
    passiontim阅读 15,085评论 2 44
  • PLEASE READ THE FOLLOWING APPLE DEVELOPER PROGRAM LICENSE...
    念念不忘的阅读 13,304评论 5 6
  • 一直活在自己小世界的人其实是蛮可悲的。 小时候总会觉得自己是那么独特,上天一定会很眷顾自己,好像什么东西自...
    小米虫儿阅读 263评论 0 0
  • 有个人很经常问我一些问题,让我烦躁又头疼。 比如昨天,问我奇葩说的题目:闺蜜约你去撕小三,你去还是不去? 我说:撕...
    陈炜杭阅读 323评论 0 0
  • 换人不换指标,有助于团队平衡健康发展。 比如说这C员工,到年中离职了,按照以前的处理方式。C的客户就会被AB...
    耶林世界阅读 264评论 0 0