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

Flutter集成Firebase静态库报错:FirebaseCoreInternal与FirebaseStorage无法集成

问题与修复方案:FirebaseCoreInternal和FirebaseStorage静态库集成失败

问题详情

尝试以静态库形式集成FirebaseCoreInternal和FirebaseStorage两个Swift Pod时失败,已尝试use_frameworks!和use_modular_headers!全局配置,仍报错:

  • Swift pod FirebaseCoreInternal依赖的GoogleUtilities未定义模块,需全局设置use_modular_headers!或为特定依赖指定:modular_headers => true生成模块映射
  • Swift pod FirebaseStorage依赖的FirebaseAppCheckInterop、FirebaseAuthInterop、FirebaseCore、FirebaseCoreExtension和GTMSessionFetcher均未定义模块,需配置模块化头文件

原Podfile内容

# 取消注释此行以定义项目全局平台
# platform :ios, '11.0'
# CocoaPods分析会同步发送网络统计数据,影响Flutter构建延迟。
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
    flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
    target 'RunnerTests' do
        inherit! :search_paths
    end
end

post_install do |installer|
    installer.pods_project.targets.each do |target|
        flutter_additional_ios_build_settings(target)
    end
end

修复方案

1. 核心配置调整

在flutter_ios_podfile_setup之前添加全局模块化头文件和静态库模式配置,确保所有依赖生成正确的模块映射:

use_modular_headers!
use_frameworks! :linkage => :static

2. 修复后的完整Podfile

# 取消注释此行以定义项目全局平台
platform :ios, '11.0' # 建议指定最低iOS版本,Firebase部分组件依赖iOS 11+
# CocoaPods分析会同步发送网络统计数据,影响Flutter构建延迟。
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)

# 全局启用模块化头文件,解决Swift Pod依赖的模块未定义问题
use_modular_headers!
# 显式指定静态库模式,适配Flutter集成
use_frameworks! :linkage => :static

flutter_ios_podfile_setup

target 'Runner' do
    flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
    target 'RunnerTests' do
        inherit! :search_paths
    end
end

post_install do |installer|
    installer.pods_project.targets.each do |target|
        flutter_additional_ios_build_settings(target)
        # 可选:针对仍有模块问题的OC库,强制开启模块映射
        target.build_configurations.each do |config|
            config.build_settings['DEFINES_MODULE'] = 'YES'
        end
    end
end

3. 执行清理与重新安装

  • 删除项目根目录下的Pods文件夹和Podfile.lock文件
  • 运行命令:flutter clean
  • 运行命令:flutter pub get
  • 运行命令:pod install --repo-update

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.14 09:22:21