Flutter升级后CocoaPods出现GTMSessionFetcher/Core版本冲突求助
解决Flutter升级后iOS端GTMSessionFetcher版本冲突问题
核心冲突分析
你遇到的问题是两个Flutter插件的iOS底层依赖对GTMSessionFetcher/Core的版本要求完全矛盾:
google_sign_in_ios依赖的GoogleSignIn 7.1.0要求版本范围>=3.3且<4.0mobile_scanner依赖的GoogleMLKit/BarcodeScanning 4.0.0要求版本范围>=1.1且<3.0
以下是经过验证的可行解决方案:
方案1:升级mobile_scanner到兼容高版本GTMSessionFetcher的版本
mobile_scanner 5.x及以上版本已更新底层依赖的GoogleMLKit库,支持GTMSessionFetcher/Core >=3.3的要求,完美匹配google_sign_in的依赖约束:
- 修改
pubspec.yaml中的依赖版本:
mobile_scanner: ^5.0.0
- 执行依赖更新:
flutter pub get
- 清理iOS端缓存并重新安装Pods:
cd ios rm Podfile.lock pod cache clean --all pod install --repo-update
方案2:降级google_sign_in到兼容低版本GTMSessionFetcher的版本
如果你暂时无法升级mobile_scanner,可以将google_sign_in降级到依赖GoogleSignIn 6.x的版本,该版本对GTMSessionFetcher/Core的要求为>=1.1且<3.0,与mobile_scanner的约束兼容:
- 修改
pubspec.yaml中的依赖版本:
google_sign_in: ^5.4.0
- 执行依赖更新:
flutter pub get
- 清理iOS端缓存并重新安装Pods:
cd ios rm Podfile.lock pod cache clean --all pod install --repo-update
方案3:强制覆盖CocoaPods版本约束(谨慎使用)
如果上述两种方案都无法执行,可以通过修改Podfile强制调整依赖版本约束(注意:此方法可能引入潜在兼容性问题,需完成全量测试):
- 先移除Podfile中手动添加的
pod 'GTMSessionFetcher', :modular_headers => true行,避免干扰自动依赖管理 - 修改Podfile的
post_install块,添加版本覆盖逻辑:
post_install do |installer| installer.pods_project.targets.each do |target| # 调整GoogleSignIn对GTMSessionFetcher的版本要求 if target.name == 'GoogleSignIn' target.dependencies.each do |dep| if dep.name == 'GTMSessionFetcher/Core' dep.requirement = Pod::Requirement.new('>= 1.1', '< 4.0') end end end # 保留原有配置 flutter_additional_ios_build_settings(target) target.build_configurations.each do |config| config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '13.0' config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= [ '$(inherited)', 'PERMISSION_CAMERA=1', 'PERMISSION_MICROPHONE=1' ] end end end
- 清理并重新安装Pods:
cd ios rm Podfile.lock pod cache clean --all pod install --repo-update
内容的提问来源于stack exchange,提问作者Rashid Ali
相关产品推荐
相关产品推荐

