安装PhoneGap CLI
创建应用
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"
目录如下:
phonegpa项目目录
启动应用
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-pairing.png
可在真机上动态调试,修改文件手机端会动态更新,对调试方便太多了,只是针对网页版的
下载apk地址通过google play下,不方便网上找的下载地址
打包 apk
生成android platform
phonegap platform add android
会在platforms 下生成android文件夹,内为完整的android studio项目,只是使用的gradle 较老
Paste_Image.png
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
插件的删除
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 create a phonegap project
build build the project for a specific platform
install install the project on for a specific platform
run 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 copies www/ into platform project before compiling
compile compiles platform project without preparing it
emulate 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