react-native热更新与打包发布

热更新流程图

打包配置确认流程

  1. config.js版本号 与 环境

    1. bundleMinVersion + 1
    2. 测试环境release包 与 正式环境release包 对应环境域名
  2. 配置热更新服务器环境,区分环境,nativeConfig.js ->
    buildConfig.DEBUG ? “http://**-test.com:3000” : “http://**-pro.com:3000”

  3. 热更新服务器登录切换 code-push whoami
    测试环境 http://**-test.com:3000
    正式环境 http://**-pro.com:3000

run-android发布

1
2
react-native run-android // debug包 
react-native run-android --variant=release // release包

生成bundle包

1
2
3
4
5
6
7
8
9
react-native bundle --platform android --entry-file index.js --bundle-output ./bundles/index.android.bundle --assets-dest ./bundles --dev false

// 解释
react-native bundle
--platform android            // 平台
--entry-file index.js         //启动文件
--bundle-output ./bundles/index.android.bundle // 打包js输出文件
--assets-dest ./bundles       // 资源输出目录
--dev true                    // 是否调试模式
  1. 调试环境 –dev true;正式环境 –dev false

提交bundle包到code-push,发布更新

  1. 获取登录的token
    http://**-test.com:3000
    用户名:admin
    密码:**

  2. 登录到code-push-server

    1
    code-push login http://******-test.com:3000

token 复制 1)中获取的 token

  1. code-push相关命令
    查看 app
    code-push app ls
    查看 Deployment Key

code-push deployment ls 组局游戏-android -k

  1. 执行code-push release命令
1
2
3
4
5
6
7
8
9
10
code-push release "组局游戏-android" ./bundles/ 0.0.3 --deploymentName Production --description "version=8" --mandatory false

// 解释
code-push release
"组局游戏-android"                // <应用名称>
./bundles/                       // <bundle所在目录>
1.0.0                            // <对应版本>
--deploymentName Staging         // 更新环境 Staging 测试环境 Production 正式环境
--description "For test bundle_version=3" // 更新描述
--mandatory false                //是否强制更新
1
2
code-push history deployment "组局游戏-android" Production // 查看历史版本
code-push deployment clear "组局游戏-android" Production // 清除版本

参考

混淆代码

启用Proguard代码混淆来缩小APK文件的大小

1
def enableProguardInReleaseBuilds = true

api