zoukankan      html  css  js  c++  java
  • react native 热更新

    一、安装codepush服务


    npm install code-push-cli -g
    code-push -v


    二、创建codepush账号

    code-push register
    code-push login
    code-push logout

    三.添加应用

    Usage: code-push app add <appName> <os> <platform>

    选项:
    -v, --version 显示版本号 [布尔]

    示例:
    app add MyApp ios react-native Adds app "MyApp", indicating that it's an iOS React Native app
    app add MyApp windows react-native Adds app "MyApp", indicating that it's a Windows React Native app
    app add MyApp android cordova Adds app "MyApp", indicating that it's an Android Cordova app

    四.查看和删除应用

    code-push app list
    code-push app remove


    五.集成codepush sdk

    1.npm install --save react-native-code-push


    六.配置ios和android

    1.安装rnpm
    npm i -g rnpm
    2.链接
    rnpm link react-native-code-push
    中途输入2个enter

    3.配置android

    只要把本地的服务器和端口随便填一个就能从codepush获得最新代码了

    4.配置ios
    1.单击项目->PROJECT->info->configurations里面点击加号->添加一个duplicate release->名称为Staging
    2.选中build settings->加号->user-defined setting->输入CODEPUSH_KEY->去命令行查code-push deployment ls -k tk_ios,接着输入key->
    debug和staging 设置成一样的。
    3.打开info.plist的Codepushdeploymentkey的内容为$(CODEPUSH_KEY)
    4.查看appdelegate,发现多了一段代码,判断开发环境和生产环境的
    #ifdef DEBUG
    jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
    #else
    jsCodeLocation = [CodePush bundleURL];
    #endif


    七.使用codepush进行热更新
    1.设置更新策略,什么时候进行更新
    下面是加载就更新的例子
    1.1导入codepush
    import codePush from 'react-native-code-push'
    1.2 在componentDidMount 中调用codePush.sync();

    2.发布更新

    1.发布测试

    code-push release-react tk_ios ios --t 1.0.0 --dev false --d Staging --des "1.改变背景为红色" --m true
    code-push release-react tk_android android --t 1.0.0 --dev false --d Staging --des "1.超大字体" --m true

    2.发布生产环境

    2.1安卓
    code-push release-react tk_android android --t 1.0.0 --dev false --d Production --des "1.修复搜索页返回bug" --m true
    2.2 ios
    code-push releaselease-react tk_ios ios --t 1.0.0 --dev false --d Production --des "1.修复搜索页返回bug" --m true

    --t 版本
    --dev 是否启用开发者模式
    --d Production ,Staging是生产环境还是测试环境
    --des 更新说明
    --m 强制更新

    查询更新
    code-push deployment ls tk_ios
    code-push deployment ls tk_android

    查询历史
    code-push deployment history tk_android Production
    code-push deployment history tk_android Staging

    3.测试
    1.需要要ios的js打包,放到xcode,要不然每次都是本地直接更新了
    react-native bundle --entry-file index.ios.js --platform ios --dev false --bundle-output release_ios/main.jsbundle --assets-dest release_ios/
    2.把打包的拉倒xcode,不要copy needed
    3.去appdelegate里面 设置jsCodeLocation = [CodePush bundleURL];,把其他注释掉

    查看push的版本

    code-push deployment history tk_android Production


    安卓的打包


    1.在项目根目录执行
    React-native bundle --entry-file index.android.js --bundle-output ./android/app/src/main/assets/index.android.jsbundle --platform android --assets-dest ./android/app/src/main/res/ --dev false

    2.在项目根目录执行

    cd android && ./gradlew assembleRelease


    http://www.devio.org/2016/07/23/react-native-%E5%8F%91%E5%B8%83APP%E4%B9%8B%E7%AD%BE%E5%90%8D%E6%89%93%E5%8C%85APK/

    问题:Couldn't follow symbolic link
    1.https://juejin.im/post/599bcdaf518825242927bd1b
    2.https://github.com/facebook/react-native/issues/11212

    问题:Duplicate file 安卓打包的时候出现

    1.解决方法是把$(rn_project)androidappsrcmain es文件夹下的带有drawable-xxxx的文件夹删掉就可以了


    问题:null is not an object(evaluating _this3._foot.setNativeProps)


    问题:can only update a mounted or mounting component, this usually means you called setstate on an unmounted component
    https://www.cnblogs.com/zyl-Tara/p/7998590.html

    https://www.jianshu.com/p/a9d1f5aa719a

    问题:安卓隐藏底部bar
    https://stackoverflow.com/questions/32704336/how-to-access-activity-from-a-react-native-android-module

    问题:Only the original thread that created a view hierarchy can touch its views

    https://developer.android.com/training/system-ui/navigation.html


    问题:如何修改安卓的包名

    进入 Androidmanifest.xml 文件,找到 package 名称,选中需要修改的部分。
    比如原包名为
    com.faqiang.android
    如果需要修改中间的 faqiang ,那么我们就选中 faqiang ,
    依次进行 右键 - > Refactor -> Rename , (Mac 快捷键为 fn + shift+F6)
    然后选择 Rename package , 输入要修改目标的名称 ,直接点击 Refactor , 左下方继续点击 Do Refactor , 等待修改成功~!

    问题:cannot add a child that doesn't have a yoganode to a parent without a message function()

    http://www.mianbeian.org/

  • 相关阅读:
    call()与apply()的作用与区别
    Tomcat8/9的catalina.out中文乱码问题解决
    怎样查看Jenkins的版本
    每日日报2020.8.18
    528. Random Pick with Weight
    875. Koko Eating Bananas
    721. Accounts Merge
    515. Find Largest Value in Each Tree Row
    286. Walls and Gates (Solution 1)
    408. Valid Word Abbreviation
  • 原文地址:https://www.cnblogs.com/norm/p/8717556.html
Copyright © 2011-2022 走看看