Flutter iOS构建报错:Swift 5.1.3编译模块无法被Swift 5.5.2导入
解决Flutter iOS构建时Swift版本不兼容问题
遇到的错误提示:Module compiled with Swift 5.1.3 cannot be imported by the Swift 5.5.2 compiler,原生iOS的Build libraries for distribution设置方案确实没法直接在Flutter项目里用,试试以下几种解决办法:
更新所有Flutter插件到最新版
执行命令flutter pub upgrade,多数插件作者会跟进Swift版本迭代,更新后大概率能解决版本不兼容问题。手动修改问题插件的iOS配置
- 打开Flutter项目的
ios目录,用Xcode打开Runner.xcworkspace - 在左侧导航栏的Pods目录下找到报错的插件,选中它的target
- 进入Build Settings,搜索
Build Libraries for Distribution,把它设为YES - 同时检查
Swift Language Version,确保和你当前Xcode的Swift版本(这里是5.5.2)一致 - 执行
flutter clean清理缓存,再重新构建项目
- 打开Flutter项目的
强制插件使用指定Swift版本
如果插件无法更新,可在ios/Podfile末尾添加以下配置,强制所有插件使用当前Swift版本:post_install do |installer| installer.pods_project.targets.each do |target| target.build_configurations.each do |config| config.build_settings['SWIFT_VERSION'] = '5.5.2' end end end执行
pod install后重新构建项目。替换不兼容插件
要是以上方法都没用,找功能类似、维护活跃的替代插件替换掉问题插件,再重新构建。
内容的提问来源于stack exchange,提问作者Aimen SAYOUD
相关产品推荐
相关产品推荐

