[Flutter] 有 Cocoapods 的專案無法用 Xcode 15 編譯
情境
將電腦更新到 MacOS 14 後,也更新了 Xcode 15 和 Flutter SDK,但原本好好的專案卻無法編譯了。環境
- Flutter 3.13
- Xcode 15
- Cocoapods 1.11.2
解題過程
舊專案在環境更新後編譯時,會回傳錯誤訊息:Error (Xcode): DT_TOOLCHAIN_DIR cannot be used to evaluate LIBRARY_SEARCH_PATHS, use TOOLCHAIN_DIR instead
具體原因尚待查明,目前的解決方法,是在 Podfile 加入改寫設定檔的程式:
installer.generated_projects.each do |project|
project.targets.each do |target|
target.build_configurations.each do |config|
xcconfig_path = config.base_configuration_reference.real_path
xcconfig = File.read(xcconfig_path)
xcconfig_mod = xcconfig.gsub(/DT_TOOLCHAIN_DIR/, "TOOLCHAIN_DIR")
File.open(xcconfig_path, "w") { |file| file << xcconfig_mod }
end
end
end
gsub 是在 ruby 中替換字串的功能。
可參考我的作品的 Git Commit
留言
張貼留言