You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何修复Xcode中'Flutter/Flutter.h'文件未找到的问题?

Flutter iOS构建失败:'Flutter/Flutter.h'文件未找到 + SwiftEmitModule错误,常规修复方案无效

上周处理项目时还能正常构建,之后转去给另一应用开发新功能,周末返回后发现两个Flutter应用都无法编译:一个报socket异常,另一个出现以下构建错误:

Could not build the precompiled application for the device.
Lexical or Preprocessor Issue (Xcode): 'Flutter/Flutter.h' file not found
/Users/user/.pub-cache/hosted/pub.dev/flutter_blue_plus-1.32.7/ios/Classes/FlutterBluePlusPlugin.h:7:8

Lexical or Preprocessor Issue (Xcode): 'Flutter/Flutter.h' file not found
/Users/user/.pub-cache/hosted/pub.dev/package_info_plus-8.0.0/ios/Classes/FPPPackageInfoPlusPlugin.h:4:8

Uncategorized (Xcode): Command SwiftEmitModule failed with a nonzero exit code

Error launching application on AR18 iPhone.

我试过了各种常规解决方法,包括针对Xcode 15的DT_TOOLCHAIN_DIR相关方案,但都没有效果。

已执行的操作:

  • 完全卸载并重新安装CocoaPods,更新仓库
  • 删除ios文件夹并多次重新生成
  • 清理Flutter项目和iOS项目缓存
  • 删除Xcode缓存文件
  • 修改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__))
  target 'RunnerTests' do
    inherit! :search_paths
  end
end

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['ENABLE_BITCODE'] = 'NO'
      config.build_settings['CLANG_ENABLE_MODULES'] = 'YES'
      config.build_settings['SWIFT_VERSION'] = '5.0'
    end
  end
end

所有操作后仍无法成功构建应用,求可行的解决方法。

内容的提问来源于stack exchange,提问作者Nissaba

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.20 15:53:17