基于 Git 的自动合并更新
react-native-git-upgrade
提供了豪华的一条龙自动合并更新流程
1. 安装 Git
你需要安装 Git,但这并不要求你自己使用 Git 去管理项目,只是我们的更新过程会使用到 Git 罢了。你可以在这里下载安装 Git,注意要把 Git 的路径添加到PATH
变量中。
2. 安装react-native-git-upgrade
工具模块
react-native-git-upgrade
工具模块提供了命令行命令,因而需要全局安装(-g):
$ npm install -g react-native-git-upgrade
$ react-native-git-upgrade
# 这样会直接把react native升级到最新版本
# 或者是:
$ react-native-git-upgrade X.Y.Z
# 这样把react native升级到指定的X.Y.Z版本
升级过程会如丝般顺滑。当然在少数情况下,取决于具体的版本和你修改的程度,Git 的合并算法也可能遭遇失败产生一些冲突,需要你人工介入。
4. 解决冲突
文件中的冲突会以分隔线隔开,并清楚的标记出处,例如下面这样:
13B07F951A680F5B00A75B9A /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
<<<<<<< ours
CODE_SIGN_IDENTITY = "iPhone Developer";
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/HockeySDK.embeddedframework",
"$(PROJECT_DIR)/HockeySDK-iOS/HockeySDK.embeddedframework",
);
=======
CURRENT_PROJECT_VERSION = 1;
>>>>>>> theirs
HEADER_SEARCH_PATHS = (
"$(inherited)",
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
"$(SRCROOT)/../node_modules/react-native/React/**",
"$(SRCROOT)/../node_modules/react-native-code-push/ios/CodePush/**",
);
上面代码中的"ours"表示你自己的代码,而"theirs"表示 React Native 的官方代码。然后你可以根据实际情况判断,选择某一方晋级,另一方出局。
以下这些是升级变更文件,升级后需要逐个检查,有冲突的按照以上方法解决
以上转载自:https://reactnative.cn/docs/upgrading/
升级可能遇到的问题:
错误一:
'config.h' file not found
error: Build input file cannot be found: '../node_modules/react-native/third-party/double-conversion-1.1.6/src/strtod.cc'
configure: error: in `../node_modules/react-native/third-party/glog-0.3.4'
❌ error: Build input file cannot be found: '/Users/rod/dev/react/testing/awesome/node_modules/react-native/third-party/double-conversion-1.1.6/src/strtod.cc'
▸ Compiling fast-dtoa.cc
❌ error: Build input file cannot be found: '/Users/rod/dev/react/testing/awesome/node_modules/react-native/third-party/double-conversion-1.1.6/src/fast-dtoa.cc'
▸ Compiling fixed-dtoa.cc
❌ error: Build input file cannot be found: '/Users/rod/dev/react/testing/awesome/node_modules/react-native/third-party/double-conversion-1.1.6/src/fixed-dtoa.cc'
▸ Compiling double-conversion.cc
❌ error: Build input file cannot be found: '/Users/rod/dev/react/testing/awesome/node_modules/react-native/third-party/double-conversion-1.1.6/src/double-conversion.cc'
▸ Compiling diy-fp.cc
❌ error: Build input file cannot be found: '/Users/rod/dev/react/testing/awesome/node_modules/react-native/third-party/double-conversion-1.1.6/src/diy-fp.cc'
▸ Compiling cached-powers.cc
❌ error: Build input file cannot be found: '/Users/rod/dev/react/testing/awesome/node_modules/react-native/third-party/double-conversion-1.1.6/src/cached-powers.cc'
▸ Compiling bignum.cc
❌ error: Build input file cannot be found: '/Users/rod/dev/react/testing/awesome/node_modules/react-native/third-party/double-conversion-1.1.6/src/bignum.cc'
** BUILD FAILED **
The following build commands failed:
CompileC /Users/rod/dev/react/testing/awesome/ios/build/Build/Intermediates.noindex/React.build/Debug-iphonesimulator/double-conversion.build/Objects-normal/x86_64/strtod.o /Users/rod/dev/react/testing/awesome/node_modules/react-native/third-party/double-conversion-1.1.6/src/strtod.cc normal x86_64 c++ com.apple.compilers.llvm.clang.1_0.compiler
CompileC /Users/rod/dev/react/testing/awesome/ios/build/Build/Intermediates.noindex/React.build/Debug-iphonesimulator/double-conversion.build/Objects-normal/x86_64/fast-dtoa.o /Users/rod/dev/react/testing/awesome/node_modules/react-native/third-party/double-conversion-1.1.6/src/fast-dtoa.cc normal x86_64 c++ com.apple.compilers.llvm.clang.1_0.compiler
CompileC /Users/rod/dev/react/testing/awesome/ios/build/Build/Intermediates.noindex/React.build/Debug-iphonesimulator/double-conversion.build/Objects-normal/x86_64/fixed-dtoa.o /Users/rod/dev/react/testing/awesome/node_modules/react-native/third-party/double-conversion-1.1.6/src/fixed-dtoa.cc normal x86_64 c++ com.apple.compilers.llvm.clang.1_0.compiler
CompileC /Users/rod/dev/react/testing/awesome/ios/build/Build/Intermediates.noindex/React.build/Debug-iphonesimulator/double-conversion.build/Objects-normal/x86_64/double-conversion.o /Users/rod/dev/react/testing/awesome/node_modules/react-native/third-party/double-conversion-1.1.6/src/double-conversion.cc normal x86_64 c++ com.apple.compilers.llvm.clang.1_0.compiler
CompileC /Users/rod/dev/react/testing/awesome/ios/build/Build/Intermediates.noindex/React.build/Debug-iphonesimulator/double-conversion.build/Objects-normal/x86_64/diy-fp.o /Users/rod/dev/react/testing/awesome/node_modules/react-native/third-party/double-conversion-1.1.6/src/diy-fp.cc normal x86_64 c++ com.apple.compilers.llvm.clang.1_0.compiler
CompileC /Users/rod/dev/react/testing/awesome/ios/build/Build/Intermediates.noindex/React.build/Debug-iphonesimulator/double-conversion.build/Objects-normal/x86_64/cached-powers.o /Users/rod/dev/react/testing/awesome/node_modules/react-native/third-party/double-conversion-1.1.6/src/cached-powers.cc normal x86_64 c++ com.apple.compilers.llvm.clang.1_0.compiler
CompileC /Users/rod/dev/react/testing/awesome/ios/build/Build/Intermediates.noindex/React.build/Debug-iphonesimulator/double-conversion.build/Objects-normal/x86_64/bignum.o /Users/rod/dev/react/testing/awesome/node_modules/react-native/third-party/double-conversion-1.1.6/src/bignum.cc normal x86_64 c++ com.apple.compilers.llvm.clang.1_0.compiler
(7 failures)
Installing build/Build/Products/Debug-iphonesimulator/awesome.app
An error was encountered processing the command (domain=NSPOSIXErrorDomain, code=22):
Failed to install the requested application
The bundle identifier of the application could not be determined.
Ensure that the application's Info.plist contains a value for CFBundleIdentifier.
Print: Entry, ":CFBundleIdentifier", Does Not Exist
Command failed: /usr/libexec/PlistBuddy -c Print:CFBundleIdentifier build/Build/Products/Debug-iphonesimulator/awesome.app/Info.plist
Print: Entry, ":CFBundleIdentifier", Does Not Exist
Error: Command failed: /usr/libexec/PlistBuddy -c Print:CFBundleIdentifier build/Build/Products/Debug-iphonesimulator/awesome.app/Info.plist
Print: Entry, ":CFBundleIdentifier", Does Not Exist
at checkExecSyncError (child_process.js:602:13)
at Object.execFileSync (child_process.js:622:13)
at Promise.then (/Users/rod/dev/react/testing/awesome/node_modules/react-native/local-cli/runIOS/runIOS.js:208:5)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:189:7)
这是缺少third-party
文件造成的。解决办法,在项目文件夹下执行:
第一步
cd node_modules/react-native/scripts && ./ios-install-third-party.sh && cd ../../../
第二步
cd node_modules/react-native/third-party/glog-0.3.5/ && ../../scripts/ios-configure-glog.sh && cd ../../../../
注意:第二步命令“golg-0.3.5”需要改成你的glog版本,比如我的是“golg-0.3.4”,则改成
cd node_modules/react-native/third-party/glog-0.3.4/ && ../../scripts/ios-configure-glog.sh && cd ../../../../
可以在以下文件夹查看你的golg,如图
第三步重启服务:npm start
错误二:
error: Build input file cannot be found: '../node_modules/react-native/Libraries/WebSocket/libfishhook.a'
这是缺少libfishhook.a
文件造成的,我们可以手动添加它,如图:
错误三:
Module @babel/runtime/helpers/interopRequireDefault does not exist in the Haste module map
解决方法:
npm add @babel/runtime
npm install
错误四:
_this._registerEvents is not a function
或
undefined is not a function(evaluating '_this.registerEvents()')
解决办法:
第一步:
添加metro-react-native-babel-preset package
npm i metro-react-native-babel-preset --save-dev
第二步:
将.babelrc文件改成
{
"presets": ["module:metro-react-native-babel-preset"]
}
第三步:
执行
npm run start --reset-cache
或
react-native start -reset-cache