美文网首页cordova
cordova配置安装

cordova配置安装

作者: _喵了个喵_ | 来源:发表于2017-08-07 15:35 被阅读0次

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

    一、系统环境配置

    准备

    首先你需要安装一些依赖包和配置环境。如果你的开发环境是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.


    相关文章

      网友评论

        本文标题:cordova配置安装

        本文链接:https://www.haomeiwen.com/subject/tahalxtx.html