安装PhoneGap CLI
官方PhoneGap CLI安装文档
npm install -g phonegap
前提要安装node.js node.js下载地址
要翻墙,过程较慢
npm镜像 参考 http://www.jianshu.com/p/fb7251740107/comments/330864
创建应用
phonegap create 项目目径 包名 应用名称
$ phonegap create path/to/myApp
$ phonegap create path/to/myApp "com.example.app" "My App"
$ phonegap create path/to/myApp --id "com.example.app" --name "My App"
$ phonegap create path/to/myApp --template hello-world
$ phonegap create path/to/myApp --copy-from ../myOtherApp
$ phonegap create path/to/myApp -src ../myOtherApp
$ phonegap create path/to/myApp --id "com.example.app" --name "My App" --copy-from ~/myOtherApp
$ phonegap create path/to/myApp --link-to ../myOtherApp
phonegap create path/to/myApp "com.example.app" "My App"
目录如下:
启动应用
phonegap serve
phonegap serve
(node:4296) fs: re-evaluating native module sources is not supported. If you are
using the graceful-fs module, please update it to a more recent version.
[phonegap] starting app server...
[phonegap] listening on 192.168.0.112:3000
[phonegap]
[phonegap] ctrl-c to stop the server
可看到在浏览器下192.168.0.112:3000即可访问
ctrl-c 命令行结束
在手机上安装PHONEGAP DEVELOPER APP
可在真机上动态调试,修改文件手机端会动态更新,对调试方便太多了,只是针对网页版的
下载apk地址通过google play下,不方便网上找的下载地址
打包 apk
生成android platform
phonegap platform add android
会在platforms 下生成android文件夹,内为完整的android studio项目,只是使用的gradle 较老
phonegap build android
正常会在build下生成output/apk文件
出错可尝试
cordova platform update android
或者进到android项目的根目录,使用gradle命令
也可以使用android studio 打开项目运行
添加插件
官方已提供以一些常用的原生态功能文档
引入其他插件
http请求插件
toast插件
支付宝插件
添加方法
phonegap plugin add cordova-plugin-http
phonegap plugin add cordova-plugin-x-toast
插件搜索
http://cordova.apache.org/plugins/
https://www.npmjs.com/
https://github.com/
插件的删除
phonegap plugin remove cordova-plugin-x-toast
phonegap的帮助信息
phonegap help
Usage: phonegap [options] [commands]
Description:
PhoneGap command-line tool.
Commands:
help [command] output usage information
create <path> create a phonegap project
build <platforms> build the project for a specific platform
install <platforms> install the project on for a specific platform
run <platforms> build and install the project for a specific platform
platform [command] update a platform version
plugin [command] add, remove, and list plugins
template [command] list available app templates
info display information about the project
serve serve a phonegap project
version output version number
push send test push notification
Additional Commands:
local [command] development on local system
remote [command] development in cloud with phonegap/build
prepare <platforms> copies www/ into platform project before compiling
compile <platforms> compiles platform project without preparing it
emulate <platforms> runs the project with the flag --emulator
cordova execute of any cordova command
Options:
-d, --verbose allow verbose output
-v, --version output version number
-h, --help output usage information
--no-update-notifier disable update notifier, to opt-out of update-notifier
change the 'optOut' property to 'true' in
~/.config/configstore/update-notifier-phonegap.yml
Examples:
$ phonegap help create
$ phonegap create path/to/my-app
$ cd my-app/
$ phonegap run ios