Cordova 是使用 HTML,CSS 和 JavaScript构建混合移动应用程序的平台。官方文档给了我们 Cordova 的定义。
“Apache Cordova是一个开源移动开发框架,它允许您使用标准的Web技术,如HTML5,CSS3和JavaScript进行跨平台开发,避免每个移动平台本机开发语言。应用程序在针对每个平台的包装内执行,并依靠符合标准的API绑定来访问每个设备的传感器,数据和网络状态。"
Cordova提供了一组设备相关的API,通过这组API,移动应用能够以JavaScript访问原生的设备功能,如摄像头、麦克风等。
$ npm install -g cordova
Cordova command-line runs on Node.js and is available on NPM. Follow platform specific guides to install additional platform dependencies. Open a command prompt or Terminal, and type npm install -g cordova.
2. Create a project
cordova create <path>.
$ cordova create myapp com.mycompany.myteam.myapp MyApp
3. Add a platform
To add a platform, type cordova platform add <platform name>
.
4. Run your app
From the command line, run cordova run <platform name>
.
5. Common next steps
cordova platform add android
To check your current set of platforms 检查您当前的平台集
cordova platform ls
likaideMacBook-Pro:myapp ale$ cordova platform ls
Installed platforms:
android 7.1.4
Available platforms:
browser ~5.0.1
ios ~4.5.4
osx ~4.0.1
windows ~6.0.0
To check if you satisfy requirements for building the platform:
cordova requirements
Run the following command to build the project for all platforms:
$ cordova build
You can optionally limit the scope of each build to specific platforms - 'ios' in this case:
$ cordova build ios
$ cordova run android
Add Plugins 添加插件 A plugin exposes a Javascript API for native SDK functionality.
你也可以使用 CLI 来启动搜索页面: $ cordova plugin search camera
To add and save the camera plugin to config.xml and package.json
$ 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
在安装 cordova 实用程序之后,你总是可以通过运行以下命令将其更新为最新版本:
$ sudo npm update -g cordova
运行 cordova-v 查看当前运行的版本。 要找到最新发布的 cordova 版本,你可以运行:
$ npm info cordova version
Customize Icons This section shows how to configure an application's icon for various platforms. Documentation about splash screen images can be found in the Cordova-Plugin-Splashscreen documentation Splashscreen plugin docs.
Plugin Upgrades 插件升级
目前还没有使用单一命令升级更改过的插件的机制。 取而代之的是,移除插件并将其添加到你的项目中,新版本将被安装:
cordova plugin rm "some-plugin"
cordova plugin add "some-plugin"
更改应用程序生成的 apk 的版本代码,请在应用程序的 config.xml 文件的 widget 元素中设置 android-versionCode 属性。 如果没有设置 android-versionCode,则将使用 version 属性确定版本代码。
对于发布签名,可以排除密码,构建系统将提示输入密码。
Please note that when opening your project in Android studio, it is recommended that you do NOT edit your code in the IDE.
Gradle Build Tool https://gradle.org/
android plugin 和 required Gradle version的对应关系
问: Downloading https://services.gradle.org/distributions/gradle-4.1-all.zip Exception in thread "main" java.net.UnknownHostException: services.gradle.org at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java :184) at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
答: 根据url下载对应zip压缩包, 并找到对应目录, Copy到对应下载文件夹