cordova

安装 cordova

Cordova命令行工具作为npm包分发。

1
$ npm install cordova -g

创建App

跳转到你维护源代码的目录中,并创建你的cordova项目:

1
$ cordova create hello com.example.hello HelloWorld
  • 第一个参数是项目目录
  • 第二个参数是 app 名称
  • 第三个参数是项目名称

添加平台

所有后续命令都需要在项目目录或者项目目录的任何子目录运行:

1
$ cd hello

给你的App添加目标平台。我们将会添加’ios’和’android’平台,并确保他们保存在了config.xml中:

1
2
$ cordova platform add ios --save
$ cordova platform add android --save

检查你当前平台设置状况:

1
$ cordova platform ls

安装构建先决条件

要构建和运行App,你需要安装每个你需要平台的SDK。另外,当你使用浏览器开发你可以添加 browser平台,它不需要任何平台SDK。

检测你是否满足构建平台的要求:

1
2
3
4
5
6
7
8
9
10
11
12
$ 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: 大专栏  cordovainstalled

Requirements check results for ios:
Apple OS X: not installed
Cordova tooling for iOS requires Apple OS X
Error: Some of requirements check failed

构建App

默认情况下, cordova create生产基于web应用程序的骨架,项目开始页面位于www/index.html 文件。任何初始化任务应该在www/js/index.js文件中的deviceready事件的事件处理函数中。

运行下面命令为所有添加的平台构建:

1
$ cordova build

你可以在每次构建中选择限制平台范围 - 这个例子中是’ios’:

1
$ cordova build ios

查看插件列表

1
$ cordova plugin ls

查看插件列表

1
cordova plugin add <插件名称 例子>

调试

1
$ cordova run android

生成发布版app

1
$ cordova build --release

Adb安装应用程序

1
$ adb  install + app路径

例:

add install /Users/deepera/ws/cordova/client/platforms/android/build/outputs/apk/android-release.apk

查看链接设备

1
$ adb devices
原文地址:https://www.cnblogs.com/lijianming180/p/12099539.html