cordova配置安裝

結合網上資料整理,分享~~~

一躲雅、系統(tǒng)環(huán)境配置

準備

首先你需要安裝一些依賴包和配置環(huán)境。如果你的開發(fā)環(huán)境是Linux或Mac,需要把下面命令寫在~/.bash_profile中抚笔,然后執(zhí)行source ~/.bash_profile。如果是windows侨拦,則需要將這些變量添加到”我的電腦”->”環(huán)境變量”中殊橙。

JDK

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

設置環(huán)境變量:

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

設置環(huán)境變量:

ANT_HOME=/path/to/ant

PATH=$ANT_HOME/bin/:$PATH

Android SDK

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

設置環(huán)境變量:

ANDROID_HOME=/path/to/sdk

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

Node.js

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

二、Cordova環(huán)境配置

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.


最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
  • 序言:七十年代末狱从,一起剝皮案震驚了整個濱河市膨蛮,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌矫夯,老刑警劉巖鸽疾,帶你破解...
    沈念sama閱讀 206,968評論 6 482
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件吊洼,死亡現(xiàn)場離奇詭異训貌,居然都是意外死亡,警方通過查閱死者的電腦和手機冒窍,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 88,601評論 2 382
  • 文/潘曉璐 我一進店門递沪,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人综液,你說我怎么就攤上這事款慨。” “怎么了谬莹?”我有些...
    開封第一講書人閱讀 153,220評論 0 344
  • 文/不壞的土叔 我叫張陵檩奠,是天一觀的道長。 經常有香客問我附帽,道長埠戳,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 55,416評論 1 279
  • 正文 為了忘掉前任蕉扮,我火速辦了婚禮整胃,結果婚禮上,老公的妹妹穿的比我還像新娘喳钟。我一直安慰自己屁使,他們只是感情好在岂,可當我...
    茶點故事閱讀 64,425評論 5 374
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著蛮寂,像睡著了一般蔽午。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上共郭,一...
    開封第一講書人閱讀 49,144評論 1 285
  • 那天祠丝,我揣著相機與錄音,去河邊找鬼除嘹。 笑死写半,一個胖子當著我的面吹牛,可吹牛的內容都是我干的尉咕。 我是一名探鬼主播叠蝇,決...
    沈念sama閱讀 38,432評論 3 401
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼年缎!你這毒婦竟也來了悔捶?” 一聲冷哼從身側響起,我...
    開封第一講書人閱讀 37,088評論 0 261
  • 序言:老撾萬榮一對情侶失蹤单芜,失蹤者是張志新(化名)和其女友劉穎蜕该,沒想到半個月后,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體洲鸠,經...
    沈念sama閱讀 43,586評論 1 300
  • 正文 獨居荒郊野嶺守林人離奇死亡堂淡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 36,028評論 2 325
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了扒腕。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片绢淀。...
    茶點故事閱讀 38,137評論 1 334
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖瘾腰,靈堂內的尸體忽然破棺而出皆的,到底是詐尸還是另有隱情,我是刑警寧澤蹋盆,帶...
    沈念sama閱讀 33,783評論 4 324
  • 正文 年R本政府宣布费薄,位于F島的核電站,受9級特大地震影響栖雾,放射性物質發(fā)生泄漏楞抡。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 39,343評論 3 307
  • 文/蒙蒙 一岩灭、第九天 我趴在偏房一處隱蔽的房頂上張望拌倍。 院中可真熱鬧,春花似錦、人聲如沸柱恤。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,333評論 0 19
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽梗顺。三九已至泡孩,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間寺谤,已是汗流浹背仑鸥。 一陣腳步聲響...
    開封第一講書人閱讀 31,559評論 1 262
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留变屁,地道東北人眼俊。 一個月前我還...
    沈念sama閱讀 45,595評論 2 355
  • 正文 我出身青樓,卻偏偏與公主長得像粟关,于是被迫代替她去往敵國和親疮胖。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 42,901評論 2 345

推薦閱讀更多精彩內容

  • afinalAfinal是一個android的ioc闷板,orm框架 https://github.com/yangf...
    passiontim閱讀 15,401評論 2 45
  • PLEASE READ THE FOLLOWING APPLE DEVELOPER PROGRAM LICENSE...
    念念不忘的閱讀 13,433評論 5 6
  • 一直活在自己小世界的人其實是蠻可悲的澎灸。 小時候總會覺得自己是那么獨特,上天一定會很眷顧自己遮晚,好像什么東西自...
    小米蟲兒閱讀 283評論 0 0
  • 有個人很經常問我一些問題性昭,讓我煩躁又頭疼。 比如昨天县遣,問我奇葩說的題目:閨蜜約你去撕小三糜颠,你去還是不去? 我說:撕...
    陳煒杭閱讀 335評論 0 0
  • 換人不換指標艺玲,有助于團隊平衡健康發(fā)展括蝠。 比如說這C員工鞠抑,到年中離職了饭聚,按照以前的處理方式。C的客戶就會被AB...
    耶林世界閱讀 291評論 0 0