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

Xcode16.3构建Flutter项目:解决'-G'选项问题后遇cloud_firestore缺失

解决Flutter iOS构建中“Module 'cloud_firestore' not found”的问题

问题背景

Xcode新手,使用Flutter 3.29.3构建iOS项目时,解决了初始的“unsupported option '-G' for target 'arm64-apple-ios14.0'”错误后,出现新错误:Module 'cloud_firestore' not found

环境信息

  • Flutter 3.29.3
  • CocoaPods 1.16.2
  • Xcode 16.3
  • Firebase iOS SDK 14.4.0

原始Podfile内容

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '15.0'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'

# BoringSSL-GRPC pod'unu sabitle
pod 'BoringSSL-GRPC', '~> 0.0.24'

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|
    # Sadece NativeTarget'larda source_build_phase işlemi uygula
    if target.respond_to?(:source_build_phase)
      target.source_build_phase.files.each do |file|
        if file.settings && file.settings['COMPILER_FLAGS']
          flags = file.settings['COMPILER_FLAGS'].split
          flags.reject! { |flag| flag == '-G' || flag == '-GCC_WARN_INHIBIT_ALL_WARNINGS' }
          file.settings['COMPILER_FLAGS'] = flags.join(' ')
        end
      end
    end
    flutter_additional_ios_build_settings(target)
    target.build_configurations.each do |config|
      config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '14.0'
      config.build_settings['EXCLUDED_ARCHS[sdk=iphonesimulator*]'] = 'arm64'
      config.build_settings['ONLY_ACTIVE_ARCH'] = 'NO'
      config.build_settings['ENABLE_BITCODE'] = 'NO'
      %w[OTHER_CFLAGS OTHER_LDFLAGS].each do |flag|
        if config.build_settings[flag]
          config.build_settings[flag] = config.build_settings[flag].gsub(/-G/, '')
        end
      end
    end
  end
end

解决方案

1. 彻底清理缓存并重新安装依赖

执行以下命令:

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

2. 移除冲突的手动Pod依赖

你的Podfile中手动固定了BoringSSL-GRPC版本,这可能与cloud_firestore依赖的版本不兼容。删除这一行:

pod 'BoringSSL-GRPC', '~> 0.0.24'

删除后重新执行pod install。

3. 调整Xcode构建配置

  • 打开Xcode,选中Runner target,进入Build Settings
  • 找到Build Options下的Build Libraries for Distribution,设置为YES
  • 检查Search Paths下的Header Search Paths,确保包含:$(inherited) "${PODS_ROOT}/Headers/Public/**"(若缺失则添加)

4. 验证Firebase配置

  • 确认GoogleService-Info.plist已正确添加到Runner target的Copy Bundle Resources中
  • 检查pubspec.yaml中cloud_firestore的版本与Firebase iOS SDK兼容,Flutter 3.29.3建议使用cloud_firestore: ^4.17.0及以上版本(可通过flutter pub outdated查看最新兼容版本)

5. 重新构建项目

在Xcode中按下Cmd+Shift+K清理构建文件夹,然后按下Cmd+R重新运行项目。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.13 02:27:03