使用 flutter 构建 iOS 项目时出现的问题

sam*_*sam 51 xcode ios flutter

升级 Xcode 15 beta 5 后,无法构建项目。

显示错误

Firebase 1 问题 DT_TOOLCHAIN_DIR 无法用于评估 LIBRARY_SEARCH_PATHS,请改用 TOOLCHAIN_DIR

FirebaseAnalytics 1 问题 DT_TOOLCHAIN_DIR 无法用于评估 LIBRARY_SEARCH_PATHS,请改用 TOOLCHAIN_DIR

尝试分解、重新安装和更新 Pod,问题并未解决。

颤振V.3.10.6

有什么办法可以解决这个问题吗?

Kyl*_*enn 61

Xcode 2023 年 10 月 15 日解决方案

下面的解决方案应该处理以下所有问题

  1. 'Flutter/Flutter.h' file not found(对我来说这与口味有关)
  2. Cycle inside Runner; building could produce unreliable results.(对我来说,这来自实时活动和小部件扩展)

第1步:更新Podfile(Flutter / Xcode 15)

post_install do |installer|
  installer.pods_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
  installer.pods_project.targets.each do |target|
      flutter_additional_ios_build_settings(target)
      target.build_configurations.each do |config|
        config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '13.0'
      end
  end
end
Run Code Online (Sandbox Code Playgroud)

第 2 步:更新构建阶段(扩展)

  1. 打开Xcode
  2. 单击项目导航器中的“Runner”(左上角)
  3. 单击侧栏中的“目标”->“跑步者”
  4. 单击“构建阶段”(顶部栏)
  5. 将“嵌入应用程序扩展”(或“嵌入基础扩展”或类似内容)移至“运行脚本”步骤(其中包括有关框架的代码)上方

如果这不起作用,请检查https://developer.apple.com/forums/thread/730974以获取更多想法。

清洁一切

flutter clean
flutter pub get
cd ios && rm podfile.lock && arch -x86_64 pod install --repo-update
Run Code Online (Sandbox Code Playgroud)

注意:此问题在最新的cocaopod 版本中已得到解决。


lar*_*rva 41

Xcode 15 似乎是旧 Cocoapods 版本的问题。此问题在 CocoaPods 版本1.13.0中已解决,

使用 Cocoapods 旧版本,您可以通过编辑 Podfile 来解决此问题,如下所示

post_install do |installer|
  installer.aggregate_targets.each do |target|
    target.xcconfigs.each do |variant, xcconfig|
      xcconfig_path = target.client_root + target.xcconfig_relative_path(variant)
      IO.write(xcconfig_path, IO.read(xcconfig_path).gsub("DT_TOOLCHAIN_DIR", "TOOLCHAIN_DIR"))
    end
  end
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      if config.base_configuration_reference.is_a? Xcodeproj::Project::Object::PBXFileReference
        xcconfig_path = config.base_configuration_reference.real_path
        IO.write(xcconfig_path, IO.read(xcconfig_path).gsub("DT_TOOLCHAIN_DIR", "TOOLCHAIN_DIR"))
      end
    end
  end
end
Run Code Online (Sandbox Code Playgroud)

  • @fphelp 更新时只需删除 Podfile.lock 文件和 Pods/ 文件夹。并再次运行 pod install。 (4认同)
  • 如果您收到:“Flutter/Flutter.h”文件未找到,另请参阅[问题](https://github.com/CocoaPods/CocoaPods/issues/12012#issuecomment-1709418017) (4认同)
  • 令人尴尬的是,Apple 不断发布其主要开发 IDE 和相关软件的 bug 版本……每个新版本的 XCode 都存在问题!EM BA RAS 唱歌!我很反感! (3认同)

Mec*_*cki 19

在发布修复程序之前,只需打开终端窗口并从项目文件夹运行以下命令:

find . -name "*.xcconfig" -type f -exec grep -l 'DT_TOOLCHAIN_DIR' {} \; \
| while IFS= read -r file; do sed -i '' 's/DT_TOOLCHAIN_DIR/TOOLCHAIN_DIR/g' "$file"; done
Run Code Online (Sandbox Code Playgroud)

之后,错误消失并且不会返回,除非您再次运行pod updatepod install,在这种情况下,您必须再次运行该命令。

  • 我认为这是一个更合适的解决方案或解决方法,因为这个问题特定于 Xcode 15 和 Cocoapods,因为它影响所有 iOS 项目,无论使用什么技术(Flutter、本机等)。这已经在这里报告了 https://github.com/CocoaPods/CocoaPods/issues/12012 这是等到官方修复的问题,所以不需要更新 pods 文件 (2认同)

小智 8

我通过以下方式解决了这些问题:

post_install do |installer|
  installer.pods_project.targets.each do |target| 
    flutter_additional_ios_build_settings(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
Run Code Online (Sandbox Code Playgroud)

如果您使用inAppWebview进行 flutter,则会出现如下错误:

解析问题(Xcode):无法构建模块“WebKit”

因此,您可以在 pubspec.yaml 文件中添加如下内容:

flutter_inappwebview:
    git:
      url: https://github.com/Estrelio/flutter_inappwebview.git
      ref: fix-xcode-17 
Run Code Online (Sandbox Code Playgroud)