HotUpgrade
1. CodePush
staging代表开发版的热更新部署,production代表生产版的热更新部署!
0.网上资料和官网最新的不一样
1.安装CodePush: npm install -g code-push-cli
2.创建CodePush账号: code-push register (会打开网页进行注册,有点卡)
3.复制 token到控制台
-
4.在CodePush服务器上注册app:
- code-push app add MyApp-iOS ios react-native
- code-push app add MyApp-Android android react-native
- 复制部署秘钥staging或(code-push deployment ls appName)
-
5.项目安装SDK:
- npm install --save react-native-code-push
- react-native link react-native-code-push
- code-push deployment ls <AppName> -k
- 复制staging 到 MainApplication.java 里deployment-key-here
- 调用sync函数
- code-push release-react MyApp-Android android
-
相关命令3
- code-push login 登陆
- code-push loout 注销
- code-push access-key ls 列出登陆的token
- code-push access-key rm <accessKye> 删除某个 access-key
-
相关命令4
- code-push app add 在账号里面添加一个新的app
- code-push app remove 或者 rm 在账号里移除一个app
- code-push app rename 重命名一个存在app
- code-push app list 或则 ls 列出账号下面的所有app
- code-push app transfer 把app的所有权转移到另外一个账号
-
- 发布更新
-
- 第一种方式:通过code-push release-react发布更新
- code-push release-react MyApp-iOS ios
- code-push release-react MyApp-Android android
- code-push release-react MyApp-iOS ios -t 1.0.0 --dev false --d Production --des "" -r 100
- 优化操作流程" --m true
- 其中参数–t为二进制(.ipa与apk)安装包的的版本;–dev为是否启用开发者模式(默认为false);–d是要发布更新的环境分Production与Staging(默认为Staging);–des为更新说明;–m 是强制更新
- 通过code-push release发布更新(收藏)
- 应用创建时有两个环境,一个是Staging,一个是Production,开发阶段用Staging,开发完成可以用code-push promote 将应用迁移到Production中
- code-push patch 应用名 Production -r 100%
- code-push promote RNCodePush-iOS Staging Production -r 20 将Staging 推到 Production 推20%的用户。
-
相关命定5
- code-push deployment add 部署
- code-push deployment rename 重命名
- code-push deployment rm 删除部署
- code-push deployment ls 列出应用的部署情况
- code-push deployment ls -k 查看部署的key
- code-push deployment history <AppName> 查看历史版本(Production 或者 Staging)
- code-push deployment clear <appName> Production or Staging // 清除历史部署记录
- code-push rollback RNCodePush-ANdroid Staging --targetRelease v4 回滚到自定版本
-
Install Metrics(安装指标)
- Active:成功安装并运行当前release的用户的数量,即表示当前下载更新部署的活跃用户数量,of 左边数会随着用户安装、卸载而 增加、减少。of右边数代表当前安装或收到部署版本的用户数,当有用户卸载App,该数值会降低。 因此它很好的解释了当前更新包有多少活跃用户,多少用户接收过这个安装包
- Total:成功安装部署当前release的用户量,只增不减
- Pending:当前release版本被下载的数量,但是还没有被安装,该值会随着用户下载安装后增加, 在卸载时降低。
更新规则
来自网络
你APP内plist文件写的版本号可能是1.0.0,所以你的reactjs打包上传的版本也要是1.0.0(而不是1.0.1这样递增),你需要和APP保持一致,然后服务器会根据你最新上传的且和APP一样的版本作为最新版。
范围表达式
* 1.2.3 仅仅只有1.2.3的版本
* *所有版本
* 1.2.x 主要版本1,次要版本2的任何修补程序版本
* 1.2.3 - 1.2.7 1.2.3版本到1.2.7版本
* >=1.2.3 <1.2.7 大于等于1.2.3版本小于1.2.7的版本
* ~1.2.3 大于等于1.2.3版本小于1.3.0的版本
* ^1.2.3 大于等于1.2.3版本小于2.0.0的版本
相关代码5.4
//通知CodePush,一个更新安装好了。当你检查并安装更新,(比如没有使用sync方法去handle的时候),这个方法必须被调用。否则CodePush会认为update失败,并rollback当前版本,在app重启时。
当使用sync方法时,不需要调用本方法,因为sync会自动调用,我没有调用,还是加上了
---------------------
作者:CrazyCodeBoy
来源:CSDN
原文:https://blog.csdn.net/fengyuzhengfan/article/details/52003798
版权声明:本文为博主原创文章,转载请附上博文链接!
public componentDidMount () {
// 必须要刷新
CodePush.notifyAppReady()
}
CodePush.sync(
options: Object,
syncStatusChangeCallback: function(syncStatus: Number),
downloadProgressCallback: function(progress: DownloadProgress)
): Promise<Number>;
传入三个参数
1. options = { installMode: CodePush.InstallMode.IMMEDIATE, updateDialog: true }
installMode (codePush.InstallMode): 安装模式,用在向CodePush推送更新时没有设置强制更新(mandatory为true)的情况下,默认codePush.InstallMode.ON_NEXT_RESTART即下一次启动的时候安装。
mandatoryInstallMode (codePush.InstallMode):强制更新,默认codePush.InstallMode.IMMEDIATE
updateDialog (UpdateDialogOptions) :可选的,更新的对话框,默认是null,包含以下属性
appendReleaseDescription (Boolean) - 是否显示更新description,默认false
descriptionPrefix (String) - 更新说明的前缀。 默认是” Description: “
mandatoryContinueButtonLabel (String) - 强制更新的按钮文字. 默认 to “Continue”.
mandatoryUpdateMessage (String) - 强制更新时,更新通知. Defaults to “An update is available that must be installed.”.
optionalIgnoreButtonLabel (String) - 非强制更新时,取消按钮文字. Defaults to “Ignore”.
optionalInstallButtonLabel (String) - 非强制更新时,确认文字. Defaults to “Install”.
optionalUpdateMessage (String) - 非强制更新时,更新通知. Defaults to “An update is available. Would you like to install it?”.
title (String) - 要显示的更新通知的标题. Defaults to “Update available”.
具体可以查看我上面的代码:
还有一个是:codePush.InstallMode,有三种模式,
一个是立即启动,nstallMode.IMMEDIATE
一个是下次启动安装:InstallMode.ON_NEXT_RESTART
一个是程序在前台,并没有从后台切换到前台的情况下用的InstallMode.ON_NEXT_RESUME
2.状态
3.进度
iOS配置时问题
1. TARGETS->Build Settings->Header Search Paths-> 添加
$(SRCROOT)/../node_modules/react
$(SRCROOT)/../node_modules/react-native-code-push (可不加)
2. 'React/RCTEventEmitter.h' file not found
1. Disable the parallel builds:
- xCode menu -> Product -> Scheme -> Manage Shemes...
- Double click on your application
- Build tab -> clear the tick on Pallelize Build
- Add react as a project dependecy
2. xCode Project Navigator -> drag React.xcodeproj from Libraries to root tree
- Build Phases Tab -> Target Dependencies -> + -> add React
安装签名
keytool -genkey -v -keystore my-release-key.keystore -alias my-key-alias -keyalg RSA -keysize 2048 -validity 10000
注意上面的my-release-key这个名字可以自己取名,同时my-key-alias也是自己取名,其中第二个名称alias参数后边的别名,在后面你在为应用签名的时候需要用到,所以暂时记录一下这个别名
添加签名
signingConfigs {
release {
storeFile file('../keystores/rn-test.keystore')
storePassword 'name'
keyAlias 'name'
keyPassword 'name'
}
}
buildTypes {
release {
signingConfig signingConfigs.release
}
}
./gradlew assembleDebug 编译并打Debug包
./gradlew assemblexiaomiDebug 编译并打xiaomi的debug包,其他类似
./gradlew assembleRelease 编译并打Release的包
./gradlew assemblexiaomiRelease 编译并打xiaomi的Release包,其他类似
./gradlew installRelease Release模式打包并安装
./gradlew uninstallRelease 卸载Release模式包