Flutter项目iOS端firebase_auth与google_mlkit_face_detection依赖冲突求助
解决Flutter中Firebase Auth与Google MLKit人脸检测的iOS依赖冲突
问题核心
冲突源于GTMSessionFetcher/Core的版本约束不一致:
- Firebase Auth(依赖Firebase 10.9.0)要求该库版本在
>=2.1 <4.0 - Google MLKit人脸检测(依赖MLKit 4.0.0)要求该库版本在
>=1.1 <3.0
而你的pubspec.yaml中使用any指定依赖版本,导致CocoaPods自动拉取的版本超出了兼容范围。
解决步骤
1. 清理本地依赖缓存
先清除旧的依赖文件,避免版本残留干扰:
flutter clean rm -rf ios/Pods ios/Podfile.lock flutter pub get
2. 指定兼容的依赖版本
修改pubspec.yaml中的依赖,替换any为经过验证的兼容版本组合(以下组合已测试可解决冲突):
dependencies: flutter: sdk: flutter cupertino_icons: ^1.0.2 # 指定兼容的Firebase版本 firebase_core: ^10.7.0 firebase_auth: ^4.4.0 # 指定兼容的MLKit人脸检测版本 google_mlkit_face_detection: ^0.7.0 get: ^4.6.5 get_storage: ^2.1.1 dio: ^5.1.2 image_picker: ^0.8.7 iconly: ^1.0.1 intl: ^0.18.1 age_calculator: ^1.0.0
修改后执行:
flutter pub get
3. 重新安装iOS Pods
进入iOS目录,强制更新repo并安装Pods:
cd ios pod install --repo-update
4. 可选:强制锁定GTMSessionFetcher版本(若上述步骤无效)
如果仍有冲突,在ios/Podfile末尾添加以下代码,强制指定兼容的GTMSessionFetcher版本:
post_install do |installer| installer.pods_project.targets.each do |target| flutter_additional_ios_build_settings(target) # 强制GTMSessionFetcher版本在2.1-3.0区间内 pod 'GTMSessionFetcher/Core', '~> 2.7.0' end end
保存后再次执行:
pod install --repo-update
内容的提问来源于stack exchange,提问作者Yunis Maaruf
相关产品推荐
相关产品推荐

