You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多
文档控制台
免费开始使用

Flutter iOS项目pod install遇Firebase等Pod版本兼容问题求助

iOS Flutter应用Pod Install版本兼容问题

问题描述

维护2022年发布的iOS Flutter应用,执行pod install时出现FirebaseCore、FirebaseInstallations、GoogleAppMeasurement的版本兼容错误,已尝试flutter cleanflutter pub upgradepod repo update、重新添加Firebase依赖、删除podfile.lock等操作,问题仍未解决。

错误日志

Ignoring strscan-3.1.0 because its extensions are not built. Try: gem pristine strscan --version 3.1.0
Analyzing dependencies
cloud_firestore: Using Firebase SDK version '11.4.0' defined in 'firebase_core'
firebase_analytics: Using Firebase SDK version '11.4.0' defined in 'firebase_core'
firebase_app_installations: Using Firebase SDK version '11.4.0' defined in 'firebase_core'
firebase_auth: Using Firebase SDK version '11.4.0' defined in 'firebase_core'
firebase_core: Using Firebase SDK version '11.4.0' defined in 'firebase_core'
firebase_in_app_messaging: Using Firebase SDK version '11.4.0' defined in 'firebase_core'
firebase_messaging: Using Firebase SDK version '11.4.0' defined in 'firebase_core'
[!] CocoaPods could not find compatible versions for pod "FirebaseCore":
  In Podfile:
    cloud_firestore (from `.symlinks/plugins/cloud_firestore/ios`) was resolved to 5.6.0, which depends on
      Firebase/Firestore (= 11.4.0) was resolved to 11.4.0, which depends on
        FirebaseFirestore (~> 11.4.0) was resolved to 11.4.0, which depends on
          FirebaseCore (~> 11.4)

    cloud_firestore (from `.symlinks/plugins/cloud_firestore/ios`) was resolved to 5.6.0, which depends on
      Firebase/Firestore (= 11.4.0) was resolved to 11.4.0, which depends on
        FirebaseFirestore (~> 11.4.0) was resolved to 11.4.0, which depends on
          FirebaseFirestoreInternal (= 11.4.0) was resolved to 11.4.0, which depends on
            FirebaseCore (~> 11.0)

    firebase_core (from `.symlinks/plugins/firebase_core/ios`) was resolved to 3.9.0, which depends on
      Firebase/CoreOnly (= 11.4.0) was resolved to 11.4.0, which depends on
        FirebaseCore (= 11.4.0)

CocoaPods could not find compatible versions for pod "FirebaseInstallations":
  In Podfile:
    firebase_app_installations (from `.symlinks/plugins/firebase_app_installations/ios`) was resolved to 0.3.1-7, which depends on
      Firebase/Installations (= 11.4.0) was resolved to 11.4.0, which depends on
        FirebaseInstallations (~> 11.4.0)

    firebase_in_app_messaging (from `.symlinks/plugins/firebase_in_app_messaging/ios`) was resolved to 0.8.0-11, which depends on
      Firebase/InAppMessaging (= 11.4.0) was resolved to 11.4.0, which depends on
        FirebaseInAppMessaging (~> 11.4.0-beta) was resolved to 11.4.0-beta, which depends on
          FirebaseInstallations (~> 11.0)

CocoaPods could not find compatible versions for pod "GoogleAppMeasurement":
  In Podfile:
    firebase_analytics (from `.symlinks/plugins/firebase_analytics/ios`) was resolved to 11.3.6, which depends on
      Firebase/Analytics (= 11.4.0) was resolved to 11.4.0, which depends on
        Firebase/Core (= 11.4.0) was resolved to 11.4.0, which depends on
          FirebaseAnalytics (~> 11.4.0) was resolved to 11.4.0, which depends on
            FirebaseAnalytics/AdIdSupport (= 11.4.0) was resolved to 11.4.0, which depends on
              GoogleAppMeasurement (= 11.4.0)

    google_mobile_ads (from `.symlinks/plugins/google_mobile_ads/ios`) was resolved to 1.0.0, which depends on
      Google-Mobile-Ads-SDK (~> 9.13) was resolved to 9.14.0, which depends on
        GoogleAppMeasurement (< 11.0, >= 7.0)

Podfile内容

# Uncomment this line to define a global platform for your project
platform :ios, '13.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.generated_projects.each do |project|
       project.targets.each do |target|
           target.build_configurations.each do |config|
               config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '13.0'
            end
       end
end
   installer.pods_project.targets.each do |target|
   flutter_additional_ios_build_settings(target)
 end
end

已执行操作

  • flutter clean
  • flutter pub upgrade
  • pod repo update
  • pod install
  • 在pubspec.yaml中删除并重新添加firebase_core、cloud_firestore、firebase_auth依赖
  • 删除podfile.lock文件

flutter doctor检测结果

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.27.1, on macOS 15.0.1 24A348 darwin-arm64, locale ja-JP)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 16.2)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2024.2)
[✓] VS Code (version 1.92.2)
[✓] Connected device (5 available)
[✓] Network resources

解决方案

核心冲突分析

最致命的冲突是GoogleAppMeasurement版本不兼容firebase_analytics依赖的Firebase SDK 11.4.0要求GoogleAppMeasurement = 11.4.0,但老旧的google_mobile_ads: 1.0.0依赖的Google-Mobile-Ads-SDK 9.14.0要求GoogleAppMeasurement < 11.0。另外Firebase内部的beta版本依赖(如InAppMessaging的beta包)也加剧了版本冲突。

步骤1:升级google_mobile_ads到兼容版本

google_mobile_ads: 1.0.0是非常老旧的版本,需要升级到支持Firebase SDK 11.x的版本。在pubspec.yaml中更新依赖:

google_mobile_ads: ^4.0.0 # 或更高的稳定版本

执行flutter pub get拉取新依赖。

步骤2:锁定Firebase SDK版本为统一兼容范围

如果升级广告插件后仍有Firebase内部冲突,在pubspec.yaml中明确指定所有Firebase插件的版本,确保它们依赖相同的Firebase SDK版本:

firebase_core: ^3.9.0
firebase_analytics: ^11.3.6
cloud_firestore: ^5.6.0
firebase_auth: ^5.3.0
firebase_messaging: ^15.1.0
# 注意:firebase_in_app_messaging的beta版本可能存在依赖问题,建议替换为稳定版
firebase_in_app_messaging: ^0.8.0 # 确认使用非beta的稳定版本

步骤3:修复Podfile中的版本兼容配置

在Podfile的target 'Runner'块中添加Firebase版本锁定,强制所有Firebase相关pod使用统一版本:

target 'Runner' do
 use_frameworks!
 use_modular_headers!

 flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))

 # 添加以下代码锁定Firebase版本
 pod 'FirebaseCore', '11.4.0'
 pod 'FirebaseInstallations', '11.4.0'
 pod 'GoogleAppMeasurement', '11.4.0'
end

步骤4:清理并重新安装依赖

执行以下命令彻底清理并重新安装:

flutter clean
rm -rf ios/Pods ios/Podfile.lock ios/Runner.xcworkspace
flutter pub get
cd ios
pod repo update
pod install --repo-update

备选方案(如果无法升级google_mobile_ads)

如果因业务限制无法升级广告插件,需要降级Firebase SDK版本到10.x,确保兼容GoogleAppMeasurement <11.0

  1. pubspec.yaml中指定Firebase插件为依赖Firebase SDK 10.x的版本:
firebase_core: ^2.24.2
firebase_analytics: ^10.14.0
cloud_firestore: ^4.17.3
firebase_auth: ^4.17.8
firebase_messaging: ^14.7.9
firebase_in_app_messaging: ^0.7.3+1
google_mobile_ads: 1.0.0
  1. 重复步骤4的清理安装操作。

内容的提问来源于stack exchange,提问作者tasmicsy

火山引擎 最新活动