Flutter iOS集成flutter_web_auth_2编译失败求助
报错信息:
Lexical or Preprocessor Issue (Xcode): 'flutter_web_auth_2/flutter_web_auth_2-Swift.h' file not found /Users/user/.pub-cache/hosted/pub.dev/flutter_web_auth_2-2.1.0/ios/Classes/FlutterWebAuth2Plugin.m:1:8
以下是你可能没试过的解决方案:
给Runner target添加空Swift文件
Xcode需要项目中存在至少一个Swift文件才会自动生成Swift-Objective-C桥接头。如果新项目移除故事板后没有Swift文件,在iOS/Runner目录下新建Dummy.swift,内容可以仅写// 触发桥接文件生成的占位文件,之后重新编译。手动配置桥接头路径
打开Xcode的Runner target → Build Settings → Swift Compiler - General → Objective-C Bridging Header,手动填入路径:$(SRCROOT)/Pods/flutter_web_auth_2/ios/Classes/flutter_web_auth_2-Bridging-Header.h,保存后清理缓存重新编译。深层清理缓存
- 删除Flutter包缓存:
rm -rf ~/.pub-cache/hosted/pub.dev/flutter_web_auth_2-2.1.0 - 进入iOS目录,删除
Podfile.lock和Pods文件夹 - 依次执行
flutter clean→flutter pub get→pod install(确保在iOS目录下执行pod install)
- 删除Flutter包缓存:
添加头文件搜索路径
在Runner target → Build Settings → Search Paths → Header Search Paths中,添加$(SRCROOT)/Pods/flutter_web_auth_2/ios/Classes,并设置为Recursive(递归搜索)。尝试降级包版本
在pubspec.yaml中将flutter_web_auth_2版本改为^2.0.0,执行flutter pub get后重新编译,排查是否是新版本与当前Flutter环境的兼容性问题。确保打开正确的Xcode文件
始终通过Runner.xcworkspace打开项目,不要直接打开Runner.xcodeproj,否则Pods依赖无法被正确加载。
内容的提问来源于stack exchange,提问作者T. Tim

