ionic3 android 热更新总结

407 阅读1分钟

1.创建ionic 项目ionic start

2.添加android平台 ionic cordova platform add android

3. 添加热更新cordova插件

ionic cordova plugin add cordova-hot-code-push-plugin
npm install -g cordova-hot-code-push-cli

4.执行cordova-hcp init 在项目根目录下生成cordova-hcp.json
cordova-hcp init
Running init
Please provide: Enter project name (required): app name
Please provide: Amazon S3 Bucket name (required for cordova-hcp deploy):
Please provide: Path in S3 bucket (optional for cordova-hcp deploy):
Please provide: Amazon S3 region (required for cordova-hcp deploy): (us-east-1)
Please provide: IOS app identifier:
Please provide: Android app identifier:
Please provide: Update method (required): (resume) start
Please provide: Enter full URL to directory where cordova-hcp build result will be uploaded:  http://123.123.0.123/www
Project initialized and cordova-hcp.json file created.
If you wish to exclude files from being published, specify them in .chcpignore
Before you can push updates you need to run "cordova-hcp login" in project directory
文件内容

{

"name": "ionic",

"ios_identifier": "",

"android_identifier": "",

"update": "start",

"content_url": "http://123.123.0.123/www" // 服务器chcp.json目录

}

5. cordova-hcp build 生成chcp.json和chcp.manifest文件

  • chcp.json: 包含发布相关信息:热更新代码版本号
  • chcp.manifest: 包含项目热更新代码文件信息:文件名和文件哈希值

6.配置config.xml文件
 

  

  

  

 

config-file:配置文件 chcp.json 从服务器上加载的路径auto-download:是否自动下载热更新代码,默认是 trueauto-install:是否自动安装热更新代码,默认是 truenative-interface:当前版本号

7.ionic项目下的www文件夹放到服务器http://123.123.0.123目录下
8.config.xml配置中定义的版本号与服务器chcp.json文件中的版本号对比