美文网首页
「React Native」升级到0.61.5

「React Native」升级到0.61.5

作者: 七月流火_9405 | 来源:发表于2020-05-20 11:00 被阅读0次

一、背景

1.苹果新上架直接被拒绝,理由是苹果商店不再接受使用UIwebview的新应用程序,应当采用WKwebview替换。


苹果审核被拒.jpg

2.升级前版本

  React Native:0.57.8  
  React 16.6.3

3.调研,升级目标版本

  React Native:0.61.5
  React 16.9.0

二、升级方式

1.采用手动升级
2.初始化一个0.61.5的rn工程,获取到package.json,得到react和react native对应的版本。
3.将需要升级的工程,手动更改package.json中的react和react native版本,以及babel/core,babel/runtime等等.

{
  "name": "Test",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "lint": "eslint --ext .js ./src --fix",
    "test": "jest"
  },
  "dependencies": {
    "react": "16.9.0",
    "react-native": "0.61.5"
  },
  "devDependencies": {
    "@babel/core": "7.8.7",
    "@babel/runtime": "7.8.7",
    "@babel/plugin-proposal-decorators": "7.3.0",
    "@babel/preset-flow": "7.0.0",
    "@types/react": "16.9.0",
    "@types/react-native": "0.61.5",
    "babel-core": "7.0.0-bridge.0",
    "babel-jest": "25.1.0",
    "babel-plugin-transform-decorators-legacy": "1.3.5",
    "babel-preset-react-native": "4.0.0",
    "eslint": "6.8.0",
    "eslint-config-airbnb": "18.0.1",
    "eslint-plugin-import": "2.20.1",
    "eslint-plugin-jsx-a11y": "6.2.3",
    "eslint-plugin-react": "7.18.3",
    "eslint-plugin-react-hooks": "1.7.0",
    "jest": "25.1.0",
    "metro-react-native-babel-preset": "0.58.0",
    "react-test-renderer": "16.9.0"
  },
  "jest": {
    "preset": "react-native"
  }
}

4.解决安卓升级问题
1)rn版本升级后,全面采用androidx,android v4和v7的老api全部废弃,三方库先升级到匹配0.61.5的版本,若版本过老,需要手动更改三方库安卓中引入v4货v7的api改为androidx包中的api。
2)gradle版本升级(4.6升级到5.5)

distributionUrl=https\://services.gradle.org/distributions/gradle-5.5-all.zip

5.解决苹果升级的问题。
1)react库重复引用的问题,原因是低版本的react未删除,新版本又接入,从而导致提示重复。
2)全面采用cocopods管理三方库,手动添加,会报React/RCTDefines.h,最开始一直卡主该问题,后面发现是三方库混合管理,部分采用cocopods,部分采用手动添加。多次编译发现,每次报错的三方库都是手动添加的三方库中的。
3)React (missing) ,只需要在schem中删除,重新添加新的react即可
4)cocopods,pod install 报错,rpc无法下载,原因是下载依赖在国外服务器,开了代理也无法克隆下来。解决方案利用缓存机制解决。去源头下载库,放入cache中。(DoubleConversion)
5)pod install失败,官方源下载会失败,换源采用清华源。清华源因为比较大,直接下载很容易失败,失败后继续下载,直至成功。

git clone https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git  ~/.cocoapods/repos/trunk

6)React/RCTLog.h file not found ,需要在podfile新增

target 'HuoChaoDuoTests' do
  inherit! :complete
  # Pods for testing
end

target 'HuoChaoDuo-tvOS' do
  # Pods for HuoChaoDuo-tvOS

  target 'HuoChaoDuo-tvOSTests' do
    inherit! :search_paths
    # Pods for testing
  end
end

7)Yoga/Yoga-prefix.pch' file not found
解决方案:

rm -rf ~/library/developer/xcode/deriveddata
rm -rf ~/.rncache

8)很多三方库变更,webview和netinfo从react native官方api中删除,需要引入@react-native-community中的react-native-webview、netinfo库

@react-native-community/netinfo
@react-native-community/react-native-webview

相关文章

网友评论

      本文标题:「React Native」升级到0.61.5

      本文链接:https://www.haomeiwen.com/subject/xtfgohtx.html