You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter项目引入cloud_firestore后iOS端编译耗时过长无法完成

Flutter添加cloud_firestore后编译耗时过长无法完成的解决方法

问题详情

  • 项目原本运行正常,添加cloud_firestore后编译耗时极长(超过40分钟仍未完成)
  • 已尝试flutter clean、pod install、删除pod文件等操作,均无效
  • 新创建的默认测试项目添加Firestore后也出现相同情况,无报错信息

环境版本

Firebase依赖版本:

firebase_core: ^2.32.0
firebase_auth: ^4.20.0
cloud_firestore: ^4.17.5

Flutter & Dart版本:

Flutter 3.22.1 • channel stable • https://github.com/flutter/flutter.git
Framework • revision a14f74ff3a (11 days ago) • 2024-05-22 11:08:21 -0500
Engine • revision 55eae6864b
Tools • Dart 3.4.1

可行解决步骤

  1. 锁定Firebase iOS SDK版本
    在ios/Podfile中添加以下配置,避免自动拉取最新大版本导致编译资源消耗过大:

    pod 'FirebaseFirestore', '10.23.0'
    pod 'FirebaseCore', '10.23.0'
    pod 'FirebaseAuth', '10.23.0'
    

    执行cd ios && pod install --repo-update,返回项目根目录后重新运行flutter run

  2. 优化Firestore编译参数
    在ios/Podfile的post_install区块中添加增量编译配置:

    post_install do |installer|
      installer.pods_project.targets.each do |target|
        flutter_additional_ios_build_settings(target)
        if target.name == 'FirebaseFirestore'
          target.build_configurations.each do |config|
            config.build_settings['SWIFT_COMPILATION_MODE'] = 'incremental'
          end
        end
      end
    end
    

    执行flutter clean && cd ios && pod deintegrate && pod install后重新编译项目

  3. 切换Flutter渠道(可选)
    部分稳定版Firebase插件与当前Flutter版本存在兼容性问题,可尝试切换到beta渠道:

    flutter channel beta
    flutter upgrade
    

    重新安装依赖后执行编译

  4. 修复CocoaPods源问题
    若使用国内镜像源导致依赖拉取缓慢,切换回官方源:

    cd ios
    pod repo remove trunk
    pod repo add trunk https://cdn.cocoapods.org/
    pod install --repo-update
    

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.23 05:16:00