React Native × Xcode 12.5 地雷

Willie
5 min readMay 3, 2021

--

工作上的地雷總是說來就來
(碎碎念:結果勞工節放假跟沒放一樣)

首先是應該很多人在 Xcode 12.5 更新後 React Native 就沒辦法在 Mac 上 build ios 的版本(大致上長得會像下方)

The following build commands failed:
CompileC /Users/harrygwinnell/Library/Developer/Xcode/DerivedData/testApp-hgqgknryyegjzjbbjfnfzrcyijmv/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/Flipper-Folly.build/Objects-normal/x86_64/DistributedMutex.o /Users/harrygwinnell/Desktop/Git.nosync/testApp/testApp/ios/Pods/Flipper-Folly/folly/synchronization/DistributedMutex.cpp normal x86_64 c++ com.apple.compilers.llvm.clang.1_0.compiler
(1 failure)

其實在之前12.5 Beta版本的時候就出現問題了 只是 facebook 方面一直沒有積極處理就是,結果就是 4/27 Xcode 更新後,一堆人炸了。

話不多說直接來講解決辦法

主要分成兩個解法

消極處理?

把Xcode還原到12.4 (https://developer.apple.com/download/more/)

積極處理?

沒有那種東西(被打
在 5/1 勞工節忙了不知道多久之後,終於查到一些端倪
國外許多高手在檢查之後發現主要原因出在 `Flipper` 身上
(https://github.com/facebook/flipper/issues/2215)
也確實有些 RN 0.64 的人在註解掉podfile裡面的 use_flipper 相關內容後RN就可以正常運作

# Enables Flipper.
#
# Note that if you have use_frameworks! enabled, Flipper will not work and
# you should disable these next few lines.
# use_flipper!
# post_install do |installer|
# flipper_post_install(installer)
# end

但問題是這終究是治標不是治本

直到有人指出這跟之前的 “Flipper-Folly” pod-spec 被更新有關
https://github.com/facebook/flipper/issues/2215
https://github.com/facebook/react-native/issues/31179

但是也發現在 RN 0.64 0.63 的錯誤原因又不一樣
部分原因出在 project.pbxproj 當中有引用Swift-5.0路徑
必須手動刪除並添加一個空的 swift bridging header 指向一個空的 swift 檔案

但是這仍然無法解決問題

針對 project.pbxproj 當中有引用Swift-5.0路徑的錯誤處理如下

  1. 更新 rct-folly
  2. 刪除 project.pbxproj 中 LIBRARY_SEARCH_PATHS 指向 swift-5.0 的路徑
  3. 設定 bridging header

最後 提供一下0.63與0.64的解決辦法

RN 0.63.x

修改RN專案下的 `ios/podfile`
將原本的

use_flipper!

改成 指定版本

use_flipper!(‘Flipper’ => ‘0.75.1’, ‘Flipper-Folly’ => ‘2.5.3’)

安裝 react-native-clean-project

yarn add -D react-native-clean-project

在 package.json 新增一段 script

"scripts": {
"clean": "react-native-clean-project"
}

執行 npm run cleanyarn clean

確認 ./ios/pods 刪除或手動刪除 ./ios/pods 資料夾後

安裝 npm install 或是 yarn
回到 ios 資料夾下執行 pod install — repo-update 更新 pods
最後 照你執行的環境的習慣啟動 RN 並 build app 到 ios 模擬器上
react-native start — reset-cache
react-native run-ios

RN 0.64.1 fix?

如果你等不及0.64.1的更新
0.64的解法與上方大同小異
差別只在 需要更新 package.json 的內容

"react-native": "0.64.0"

更新成

"react-native": "facebook/react-native#cf8a364767df830d7255339741350bb53ab1a68a"

然後照著0.63的步驟跑一遍即可

ref: https://github.com/facebook/react-native/issues/31179#issuecomment-830184757

如果我的文章有幫助到你解決問題 請不要吝嗇掌聲
在左下角拍手的按鈕按下去 給我掌聲讓我有動力繼續寫下去

--

--

Willie
Willie

Written by Willie

just willie, Taiwanese, front-end engineer, speak Traditional Chinese and JavaScript, like the cat🐅🐆🐈, I like other guys call me Big Cat

No responses yet