CodePush

参考文章:
(最简单简洁)React Native 热更新Appcenter codepush,Android
*****[(最详细)CodePush热更新详细接入教程]https://www.jianshu.com/p/6a5e00d22723
react-native热更新之CodePush详细介绍及使用方法
CodePush热更新常用命令与注意事项

一、codepush 官方文档
CodePush
Appcenter
主要包括:1、工作过程
2、和React-Native相对应的版本
3、支持的组件

二、安装和配置
1、推荐使用appcenter
(1)、appcenter.ms,注册,登录
(2)、安装appcenter

//appcenter-analytics and appcenter-crashes  根据自己项目是否使用酌情安装
//npm
npm install appcenter appcenter-analytics appcenter-crashes --save-exact
// 或者
//yarn
yarn add appcenter appcenter-analytics appcenter-crashes --exact

(3)、创建appcenter账号和app,获取key值

//登录,没有账号先注册
appcenter login
//创建一个app
appcenter apps create -d  -o   -p 
//eg.
appcenter apps create -d MyAppName -o iOS  -p React-Native
//查询当前的App有那些
appcenter apps list
//为app添加部署的环境
appcenter codepush deployment add -a *****/MyAppName Staging
//查询key值
 appcenter codepush deployment list -a *****/MyAppName
//很有用的查询命令行书写方式
--help

2、安装codepush

yarn add react-native-code-push //安装插件
react-native link react-native-code-push //自动配置ios和安卓(最好先添加完配置信息再link)

//在原生iOS上如果使用pod,也可以代替link
pod repo update

但是还需要手动配置一些信息
(一)、iOS
(1)选中工程文件,info,添加一个Staging


CodePush_第1张图片
info.png

(2)build setting----> build location ----> production path---->

$(BUILD_DIR)/Release$(EFFECTIVE_PLATFORM_NAME)
CodePush_第2张图片
set.png

(3)build setting 点击 + ,添加 Add User-Defined Setting,更改为CODEPUSH_KEY
给Staging和Production添加key


CodePush_第3张图片
2018-11-07 at 3.59 PM.png

(4) 在info.plist 中添加CodePushDeploymentKey,相应的$(CODEPUSH_KEY)把刚才的codepush_key添加进去

屏幕快照 2019-02-12 下午5.01.19.png

(2)安卓配置方式
修改app的build.gradle

android {
    ...
    buildTypes {
        debug {
            ...
            // Note: CodePush updates should not be tested in Debug mode as they are overriden by the RN packager. However, because CodePush checks for updates in all modes, we must supply a key.
            buildConfigField "String", "CODEPUSH_KEY", '""'
            ...
        }
        releaseStaging {
            ...
            buildConfigField "String", "CODEPUSH_KEY", '""'
            ...
        }
        release {
            ...
            buildConfigField "String", "CODEPUSH_KEY", '""'
            ...
        }
    }
    ...
}

三、发布更新
1)、添加codepush代码
(2)发布更新

//部署Staging环境(不填写-d ,默认是Staging,如果直接使用release-react 。。。-d Production,就相当于直接部署到了发布到了Production上)
appcenter codepush release-react -a *****/MyAppName --description “changeContent” -t 1.0.0
//将Staging环境发布到Production正式环境上
appcenter codepush promote -a *****/MyAppName   -s Staging -d Production

四、报错问题解决
1、'CodePush/CodePush.h' file not found
解决方案: (1)、先查看build setting----> build location ----> production path---->

$(BUILD_DIR)/Release$(EFFECTIVE_PLATFORM_NAME) 

有没有更改
(2)、如果是先react-native link react-native-code-push,再配置key等信息,那就再link一次
(3)、以上两项确认无误, command+ k ,关闭xcode , 重启

五、ReactNative使用CodePush必备先知:
1、RN版本在0.34之后
2、运行环境:android4.1和iOS9.0后
3、在iOS上没有使用其他的崩溃报告第三方库
4、在iOS上,默认的使用方式依赖Cocoapods

六、使用过程
1、当创建了app之后,会出现相应运行环境的发送请求,此请求表示是否发送通知邮件给app的使用账户

What secret does your Android app use? [None]

What secret does your iOS app use? [None]

Learn more about sending user events manually.

你可能感兴趣的:(CodePush)