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

Flutter添加依赖后无法执行flutter run与pod install的问题

解决Flutter应用Firebase依赖冲突与构建失败问题

1. 统一Firebase依赖版本

Firebase各组件版本必须匹配,直接在pubspec.yaml里强制统一兼容版本:

dependency_overrides:
  cloud_firestore: 3.5.1
  firebase_core: ^1.24.0 # 选择与cloud_firestore 3.5.1兼容的版本
  # 其他Firebase相关依赖(如firebase_auth、firebase_storage等)也同步到对应兼容版本

执行命令更新依赖:

flutter pub get

2. 提升iOS最低部署目标

Firebase 9.x系列要求iOS最低部署版本为12.0,修改两处配置:

  • 打开ios/Podfile,将platform :ios, '10.0'(或当前版本)改为:
    platform :ios, '12.0'
    
  • 打开ios/Runner.xcworkspace,在Xcode中检查项目的「Deployment Target」,确保与Podfile设置一致。

3. 清理缓存并解决ffi架构冲突

彻底清理冗余缓存,同时修复M1/M2芯片的架构不兼容问题:

  1. 执行清理命令:
    flutter clean
    cd ios
    pod deintegrate
    rm -rf Podfile.lock Pods .symlinks Flutter/Flutter.podspec Flutter/Generated.xcconfig
    rm -rf ~/Library/Caches/CocoaPods
    rm -rf ../.pub-cache
    
  2. 在ios/Podfile的post_install区块添加架构兼容配置:
    post_install do |installer|
      installer.pods_project.targets.each do |target|
        flutter_additional_ios_build_settings(target)
        # 修复模拟器架构不兼容问题
        target.build_configurations.each do |config|
          config.build_settings['ARCHS[sdk=iphonesimulator*]'] = 'x86_64'
        end
      end
    end
    
  3. 更新Pods仓库并重新安装:
    pod repo update
    pod install
    

4. 验证构建

回到项目根目录,执行:

flutter run

确认应用能正常编译运行。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.02 06:00:47