升级Xcode 15后Flutter项目报错:'Flutter/Flutter.h'文件未找到
报错信息
无法为设备构建预编译应用。
Swift Compiler Error (Xcode): 'Flutter/Flutter.h' file not found
/Users/pedrocovarrubias/.pub-cache/hosted/pub.dev/vibration-1.8.2/ios/Classes/VibrationPlugin.h:0:8
Swift Compiler Error (Xcode): Could not build Objective-C module 'vibration'
已尝试操作
- 备份Runner文件夹
- 删除ios文件夹并重新执行
flutter create . - 恢复备份的Runner文件夹
- 执行
pod deintegrate、pod install - 执行
flutter clean、flutter pub get、flutter run - 重新导入GoogleService-Info.plist
pod install后提示
[!] CocoaPods未设置项目的基础配置,因为项目已有自定义配置。请将Runner目标的基础配置设置为
Target Support Files/Pods-Runner/Pods-Runner.profile.xcconfig,或在构建配置(Flutter/Release.xcconfig)中包含该文件。
[!]Runner [Debug]目标覆盖了Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig中定义的ENABLE_BITCODE构建设置,建议使用$(inherited)标志或移除目标中的该设置。
[!]Runner [Release]目标覆盖了Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig中定义的ENABLE_BITCODE构建设置,建议使用$(inherited)标志或移除目标中的该设置。
[!]Runner [Profile]目标覆盖了Pods/Target Support Files/Pods-Runner/Pods-Runner.profile.xcconfig中定义的ENABLE_BITCODE构建设置,建议使用$(inherited)标志或移除目标中的该设置。
解决方案
1. 修复CocoaPods基础配置引用
打开ios目录下的Runner.xcworkspace,选中Runner目标,切换到Build Settings标签:
- 搜索
Base Configuration,分别为Debug、Release、Profile三个配置项设置对应文件:- Debug:
Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig - Release:
Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig - Profile:
Pods/Target Support Files/Pods-Runner/Pods-Runner.profile.xcconfig
- Debug:
- 若需保留自定义xcconfig,可在你的自定义配置文件(如
Flutter/Release.xcconfig)末尾添加:#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"(对应不同配置替换后缀)
2. 修复ENABLE_BITCODE继承问题
在Runner目标的Build Settings中搜索ENABLE_BITCODE:
- 将Debug、Release、Profile三个配置的
ENABLE_BITCODE值改为$(inherited),或直接删除该自定义设置,让项目继承Pods的配置
3. 重新构建依赖
回到项目根目录,依次执行以下命令:
flutter clean rm -rf ios/Pods ios/Podfile.lock ios/Runner.xcworkspace flutter pub get cd ios && pod install
4. 更新vibration插件(若上述步骤无效)
旧版本vibration插件可能不兼容Xcode 15,修改pubspec.yaml中的依赖为最新版本(可查询pub.dev获取最新号):
vibration: ^1.8.4
执行flutter pub get后重新尝试构建。
内容的提问来源于stack exchange,提问作者PedroCova

