Table of Contents
前言
2023.9.18 蘋果終於全家桶升級
唯獨 macOS 僅僅是推出了 RC
但考慮了再三,還是升級了
升級伴隨而來的就是 Xcode 15.0
我想有很多人都發現自己的 Flutter 專案
出現了 Xcode DT_TOOLCHAIN_DIR Error
Failed to build iOS app
升級完 Xcode
想要來試試最新的 iPhone 15 Pro 的模擬器時
卻看到 Flutter 報下面這個錯誤
每個人依賴的套件不同
以我來說,拿掉 Firebase
就可以順利編譯
但不是每個專案的某個依賴都可以直接拔掉
Work Around
DT_TOOLCHAIN_DIR
既然已經說要用 TOOLCHAIN_DIR
取代
那就調整一下 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
這個時候再試試看編譯
過了!
附上完整的 Podfile
# Uncomment this line to define a global platform for your project
platform :ios, '13.0'
# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'
project 'Runner', {
'Debug' => :debug,
'Profile' => :release,
'Release' => :release,
}
def flutter_root
generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__)
unless File.exist?(generated_xcode_build_settings_path)
raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first"
end
File.foreach(generated_xcode_build_settings_path) do |line|
matches = line.match(/FLUTTER_ROOT\=(.*)/)
return matches[1].strip if matches
end
raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get"
end
require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)
flutter_ios_podfile_setup
target 'Runner' do
use_frameworks!
use_modular_headers!
flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
end
post_install do |installer|
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
installer.pods_project.targets.each do |target|
flutter_additional_ios_build_settings(target)
end
end
總結
其實還是等到 COCOAPODS
, Flutter
跟那些套件更新
問題就會解決
現在只是用一個快速的 Work around,撐過這一小段時間