Flutter配置多build flavors后iOS导出ipa报错module 'camera' not found
Flutter iOS多环境打包
module 'camera' not found报错解决方案 这个报错的核心原因是你新增的自定义构建配置(如你用到的Alpha、Debug-integration)没有同步适配CocoaPods的配置规则,导致Flutter生成的插件注册文件无法找到对应的插件模块。
1. 适配Podfile的自定义配置
打开ios/Podfile,在文件开头补充所有你项目中用到的自定义构建配置映射,修改post_install逻辑适配自定义配置:
platform :ios, '12.0' # 替换为你项目实际的最低支持iOS版本 # 新增:所有自定义构建配置的类型映射,键为Xcode中配置的名称,值为debug/release类型 custom_config_types = { 'Debug' => :debug, 'Debug-development' => :debug, 'Debug-Alpha' => :debug, 'Debug-integration' => :debug, 'Release' => :release, 'Release-development' => :release, 'Release-Alpha' => :release, 'Release-integration' => :release, # 有其他自定义配置继续按格式添加即可 } # 原有其他Podfile逻辑... post_install do |installer| installer.pods_project.targets.each do |target| flutter_additional_ios_build_settings(target) end # 新增:同步自定义配置到Pods项目 installer.pods_project.build_configurations.each do |config| if config.name.downcase.include?('debug') config.build_settings['CONFIGURATION'] = 'Debug' else config.build_settings['CONFIGURATION'] = 'Release' end end end
2. 清理缓存重新生成依赖
在项目根目录执行以下命令,清理旧的构建缓存和Pods依赖:
flutter clean rm -rf ios/Pods ios/Podfile.lock rm -rf ~/Library/Developer/Xcode/DerivedData/Runner-* cd ios && pod install --repo-update cd ..
3. 修正打包命令参数
你之前的xcodebuild命令中-configuration Alpha需要和Xcode中development scheme绑定的构建配置名称完全一致,不要填错。如果不需要自定义xcodebuild逻辑,直接用Flutter官方打包ipa的命令即可,会自动处理配置匹配:
flutter build ipa --flavor development
4. 验证Xcode配置
打开ios/Runner.xcworkspace,进入Runner项目的Info标签,确认Configurations下所有自定义配置的Based on Configuration File都选择了Pods对应的配置文件,不要设置为None。
内容的提问来源于stack exchange,提问作者Wim
相关产品推荐
相关产品推荐

