Flutter项目添加Firebase后CocoaPods报FirebaseCore版本兼容错误
解决Flutter项目中FirebaseCore与google_ml_kit的CocoaPods版本冲突问题
错误信息
[!] CocoaPods could not find compatible versions for pod "FirebaseCore": In Podfile: firebase_core (from `.symlinks/plugins/firebase_core/ios`) was resolved to 2.4.0, which depends on Firebase/CoreOnly (= 10.3.0) was resolved to 10.3.0, which depends on FirebaseCore (= 10.3.0) google_ml_kit (from `.symlinks/plugins/google_ml_kit/ios`) was resolved to 0.6.0, which depends on GoogleMLKit/LinkFirebase (~> 2.2.0) was resolved to 2.2.0, which depends on MLKitLinkFirebase (~> 1.3.0) was resolved to 1.3.0, which depends on FirebaseCore (~> 8.0)
当前Podfile内容
# Uncomment this line to define a global platform for your project platform :ios, '11.0' # CocoaPods analytics sends network stats synchronously affecting flutter build latency. ENV['COCOAPODS_DISABLE_STATS'] = 'true' project 'Runner', { 'Debug' => :debug, 'Profile' => :release, 'Release' => :release, } def flutter_root generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__) unless File.exist?(generated_xcode_build_settings_path) raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first" end File.foreach(generated_xcode_build_settings_path) do |line| matches = line.match(/FLUTTER_ROOT\=(.*)/) return matches[1].strip if matches end raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get" end require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root) flutter_ios_podfile_setup target 'Runner' do use_frameworks! use_modular_headers! flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__)) end post_install do |installer| installer.pods_project.targets.each do |target| flutter_additional_ios_build_settings(target) end end
已尝试的无效步骤
flutter cleanflutter build iospod installpod updatepod repo updatepod install --repo-update- 删除Pods文件夹
- 删除Podfile.lock文件后重新执行
pod install
可行解决方案
方案1:降级firebase_core到兼容版本
google_ml_kit 0.6.0依赖FirebaseCore ~>8.0,对应flutter的firebase_core需使用1.x系列版本(如1.24.0)。修改pubspec.yaml:
firebase_core: ^1.24.0
执行以下命令:
flutter pub get- 进入ios目录执行
pod install
方案2:升级google_ml_kit到支持高版本Firebase的版本
查看google_ml_kit最新版本,更新至兼容FirebaseCore 10.x的版本(如0.17.0及以上)。修改pubspec.yaml:
google_ml_kit: ^0.17.0 # 或更高兼容版本
执行以下命令:
flutter pub get- 进入ios目录执行
pod install --repo-update
方案3:强制指定FirebaseCore版本(不推荐)
若上述方案无法实施,可在Podfile的target 'Runner' do块内添加强制指定语句:
pod 'FirebaseCore', '~> 8.0'
然后删除Podfile.lock和Pods文件夹,执行pod install
内容的提问来源于stack exchange,提问作者Taco
相关产品推荐
相关产品推荐

