基於Git的自動合併更新
重要提示: 現在你不需要運行npm install去下載新版本的React Native了,按照下面的步驟即可自動進行更新。
1. 安裝Git
你需要安裝Git,但這並不要求你自己使用Git去管理項目。只是我們的更新過程會使用到Git罷了。你可以在這裏下載安裝Git,注意要把git的路徑添加到PATH
變量中。
2. 安裝react-native-git-upgrade
工具模塊
$ npm install -g react-native-git-upgrade
react-native-git-upgrade
提供了豪華的一條龍自動合併更新流程,主要包含兩個服務:
- 首先它會利用Git工具計算新舊版本文件間的差異並生成補丁
- 然後在用戶的項目文件上應用補丁
3. 運行更新命令
$ 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的官方代碼。然後你可以根據實際情況判斷,選擇某一方晉級,另一方出局
5.ios升級之後的問題解決
(1)'boost/iterator/iterator_adaptor.hpp' file not found(0.44升級到新版本)
Description
iOS build fails on newly created react-native project on 0.45.0.
Reproduction Steps and Sample Code
$ react-native init boostless
$ cd boostless
$ react-native run-ios
Truncated result:
** BUILD FAILED **
The following commands produced analyzer issues:
Analyze /Users/<MASKED>/boostless/node_modules/react-native/ReactCommon/yoga/yoga/YGNodeList.c
Analyze /Users/<MASKED>/boostless/node_modules/react-native/ReactCommon/yoga/yoga/Yoga.c
(2 commands with analyzer issues)
The following build commands failed:
PhaseScriptExecution Install\ Third\ Party /Users/<MASKED>/boostless/ios/build/Build/Intermediates/React.build/Debug-iphonesimulator/double-conversion.build/Script-190EE32F1E6A43DE00A8543A.sh
(1 failure)
Installing build/Build/Products/Debug-iphonesimulator/boostless.app
An error was encountered processing the command (domain=NSPOSIXErrorDomain, code=2):
Failed to install the requested application
An application bundle was not found at the provided path.
Provide a valid path to the desired application bundle.
Print: Entry, ":CFBundleIdentifier", Does Not Exist
Command failed: /usr/libexec/PlistBuddy -c Print:CFBundleIdentifier build/Build/Products/Debug-iphonesimulator/boostless.app/Info.plist
Print: Entry, ":CFBundleIdentifier", Does Not Exist
解決辦法
It's a work around:
Download+extract boost 1.63 and copy to node_modules/react-native/third-party/boost_1_63_0
Additional Information
- React Native version: 0.45.0
- Platform: iOS
- Development Operating System: macOS Sierra, 10.12.5
- Dev tools: Xcode 8.3.2 (8E2002)