Flutter在CodeMagic编译iOS应用报错:'file_picker'未找到
iOS编译失败:module 'file_picker' not found
问题背景
无Mac设备,通过CodeMagic编译Flutter应用,Android端运行正常,iOS端编译报错:
/Users/builder/clone/ios/Runner/GeneratedPluginRegistrant.m:12:9: fatal error: module 'file_picker' not found
@import file_picker;1 error generated.
当前配置:
- Podfile:
# Uncomment the next line to define a global platform for your project platform :ios, '11.0' target 'Runner' do # Comment the next line if you don't want to use dynamic frameworks use_frameworks! # Pods for Runner end
- pubspec.yaml中
file_picker: ^4.6.1
解决步骤
- 升级iOS最低版本要求
file_picker 4.6.1的官方要求是iOS最低版本12.0,当前Podfile设置的11.0不兼容,会导致依赖未正确拉取。修改Podfile:
platform :ios, '12.0'
- 清理缓存并重新安装依赖
在CodeMagic的编译流程中添加以下操作:
- 执行
flutter clean清理项目缓存 - 执行
flutter pub get重新获取Flutter依赖 - 进入ios目录执行
pod deintegrate移除现有Pod配置 - 执行
pod install --repo-update更新Pod仓库并重新安装所有依赖
- 检查CodeMagic构建配置
确保CodeMagic的iOS构建环节:
- 勾选了"Install CocoaPods dependencies"选项
- 使用的Xcode版本支持iOS 12.0及以上(推荐Xcode 13或更高版本)
- 临时替换导入方式(可选应急方案)
如果上述方法无效,可临时修改GeneratedPluginRegistrant.m中的导入语句:
将@import file_picker;替换为:
#import <file_picker/file_picker-Swift.h>
注意:此为临时 workaround,优先通过前两步解决版本兼容的根本问题。
内容的提问来源于stack exchange,提问作者casleandro
相关产品推荐
相关产品推荐

