3分钟完成React-Native热更新
来源:互联网 发布:安倍为什么能连任 知乎 编辑:程序博客网 时间:2024/06/05 20:44
此文使用当下最新版本的RN
与Code-Push
进行演示,其中的参数不会过多进行详细解释,更多参数解释可参考其它文章,这里只保证APP能正常进行热更新操作,方便快速入门,开始来快活吧。
操作指南
以下操作在Mac系统上完成
项目地扯https://github.com/dounine/dounineApp
Branches:3分钟完成React-Native热更新
1. 创建React-Native
项目
react-native init dounineApp
2. 安装code-push-cli
npm install -g code-push-cli
3. 注册code-push
帐号
code-push registerPlease login to Mobile Center in the browser window we've just opened.Enter your token from the browser: #会弹出一个浏览器,让你注册,可以使用github帐号对其进行授权,授权成功会给一串Token,点击复制,在控制进行粘贴回车(或者使用code-push login命令)。
Enter your token from the browser: b0c9ba1f91dd232xxxxxxxxxxxxxxxxx#成功提示如下方Successfully logged-in. Your session file was written to /Users/huanghuanlai/.code-push.config. You can run the code-push logout command at any time to delete this file and terminate your session.
4. 在code-push
添加一个ios的app
code-push app add dounineApp-ios ios react-native#成功提示如下方Successfully added the "dounineApp-ios" app, along with the following default deployments:┌────────────┬──────────────────────────────────────────────────────────────────┐│ Name │ Deployment Key │├────────────┼──────────────────────────────────────────────────────────────────┤│ Production │ yMAPMAjXpfXoTfxCd0Su9c4-U4lU6dec4087-57cf-4c9d-b0dc-ad38ce431e1d │├────────────┼──────────────────────────────────────────────────────────────────┤│ Staging │ IjC3_iRGEZE8-9ikmBZ4ITJTz9wn6dec4087-57cf-4c9d-b0dc-ad38ce431e1d │└────────────┴──────────────────────────────────────────────────────────────────┘
5. 继续在code-push
添加一个android的app
code-push app add dounineApp-android android react-native#成功提示如下方Successfully added the "dounineApp-android" app, along with the following default deployments:┌────────────┬──────────────────────────────────────────────────────────────────┐│ Name │ Deployment Key │├────────────┼──────────────────────────────────────────────────────────────────┤│ Production │ PZVCGLlVW-0FtdoCF-3ZDWLcX58L6dec4087-57cf-4c9d-b0dc-ad38ce431e1d │├────────────┼──────────────────────────────────────────────────────────────────┤│ Staging │ T0NshYi9X8nRkIe_cIRZGbAut90a6dec4087-57cf-4c9d-b0dc-ad38ce431e1d │└────────────┴──────────────────────────────────────────────────────────────────┘
6. 在项目根目录添加react-native-code-push
npm install react-native-code-push --save#或者yarn add react-native-code-push
7. link react-native-code-push
react-native linkScanning folders for symlinks in /Users/huanghuanlai/dounine/oschina/dounineApp/node_modules (8ms)? What is your CodePush deployment key for Android (hit <ENTER> to ignore) T0NshYi9X8nRkIe_cIRZGbAut90a6dec4087-57cf-4c9d-b0dc-ad38ce431e1d#将刚才添加的Android App的Deployment Key复制粘贴到这里,复制名为Staging测试Deployment Key。rnpm-install info Linking react-native-code-push android dependency rnpm-install info Android module react-native-code-push has been successfully linked rnpm-install info Linking react-native-code-push ios dependency rnpm-install WARN ERRGROUP Group 'Frameworks' does not exist in your Xcode project. We have created it automatically for you.rnpm-install info iOS module react-native-code-push has been successfully linked Running ios postlink script? What is your CodePush deployment key for iOS (hit <ENTER> to ignore) IjC3_iRGEZE8-9ikmBZ4ITJTz9wn6dec4087-57cf-4c9d-b0dc-ad38ce431e1d#继续复制Ios的Deployment KeyRunning android postlink script
8. 在react-native
的App.js
文件添加自动更新代码
...import codePush from "react-native-code-push";const codePushOptions = { checkFrequency: codePush.CheckFrequency.MANUAL };export default class App extends Component<{}> { componentDidMount(){ codePush.sync({ updateDialog: true, installMode: codePush.InstallMode.IMMEDIATE, mandatoryInstallMode:codePush.InstallMode.IMMEDIATE, //deploymentKey为刚才生成的,打包哪个平台的App就使用哪个Key,这里用IOS的打包测试 deploymentKey: 'IjC3_iRGEZE8-9ikmBZ4ITJTz9wn6dec4087-57cf-4c9d-b0dc-ad38ce431e1d', }); } ...
9. 运行项目在ios模拟器上
react-native run-ios
如图下所显
1:开启debug调试
2:CodePush
已经成功运行
目前App已经是最新版本
10. 发布一个ios新版本
code-push release-react dounineApp-ios ios#发布成功如图下Detecting ios app version:Using the target binary version value "1.0" from "ios/dounineApp/Info.plist".Running "react-native bundle" command:node node_modules/react-native/local-cli/cli.js bundle --assets-dest /var/folders/m_/xcdff0xd62j4l2xbn_nfz00w0000gn/T/CodePush --bundle-output /var/folders/m_/xcdff0xd62j4l2xbn_nfz00w0000gn/T/CodePush/main.jsbundle --dev false --entry-file index.js --platform iosScanning folders for symlinks in /Users/huanghuanlai/dounine/oschina/dounineApp/node_modules (10ms)Scanning folders for symlinks in /Users/huanghuanlai/dounine/oschina/dounineApp/node_modules (10ms)Loading dependency graph, done.bundle: startbundle: finishbundle: Writing bundle output to: /var/folders/m_/xcdff0xd62j4l2xbn_nfz00w0000gn/T/CodePush/main.jsbundlebundle: Done writing bundle outputReleasing update contents to CodePush:Upload progress:[==================================================] 100% 0.0sSuccessfully released an update containing the "/var/folders/m_/xcdff0xd62j4l2xbn_nfz00w0000gn/T/CodePush" directory to the "Staging" deployment of the "dounineApp-ios" app.
11. 重新Load刷新应用
12. 安卓发布
与上面9~11步骤是一样的,命令改成Android对应的,以下命令结果简化
#1.修改App.js的deploymentKey为安卓的...deploymentKey:'T0NshYi9X8nRkIe_cIRZGbAut90a6dec4087-57cf-4c9d-b0dc-ad38ce431e1d'...#2.运行react-native run-android#3.发布code-push release-react dounineApp-android android#4.刷新应用,如下图
至此已经完成RN
热更新,进阶内容请参考其它文章。
阅读全文
0 0
- 3分钟完成React-Native热更新
- react native热更新
- React Native热更新
- react-native 热更新(android)
- React Native 热更新实现
- React Native-Pushy热更新
- React Native热更新方案
- React-Native 热更新 CodePush
- React-Native 热更新以及增量更新
- React Native 热更新的组件react-native-pushy
- CodePush 热更新React-Native(ios)
- React Native 热更新 注意点1
- react-native热更新闪屏问题
- React-Native 热更新尝试(Android)
- react native搭建私有热更新服务器
- 微软的React Native热更新
- React-native 热更新之pushy!
- React-Native 热更新尝试(Android)
- 使用HD Tune扫描一块1TB的机械硬盘需要多长时间?
- phpexcel导出导入
- 笔记 34 | java线程之Thread线程优先
- SpringBoot 中文手册 --Part IV --37-40
- Android 使用Retrofit自定义Converter解析相同接口返回不同数据
- 3分钟完成React-Native热更新
- anaconda 安装opencv3
- Angular入门-语法支持
- arcgisAPI 4.5本地部署,图标样式访问不到解决办法!!
- 在安卓机上测试内联汇编和直接写成.s文件以及C语言的速率比较
- TCP保持在FIN-WAIT-2状态的请求断开
- 在anaconda2下和cmd下进行sklearn安装的不同--python2.7
- Ext事件机制(二)--组件事件
- MySQL主从复制