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

Flutter iOS构建报错:Module 'firebase_analytics'未找到(FCM集成场景)

解决Flutter集成FCM时iOS构建报错:Module 'firebase_analytics' not found

错误信息

Parse Issue (Xcode): Module 'firebase_analytics' not found
/Users/song-yunseo/Documents/bubble_app/ios/Runner/GeneratedPluginRegistrant.m:11:8

问题分析

从你提供的Podfile来看,手动添加了Firebase原生Pod依赖,但Flutter的Firebase插件(如firebase_analytics、firebase_messaging)本身会通过Flutter的podhelper自动管理对应的原生依赖,手动重复添加容易导致依赖冲突或模块识别异常。

解决方案

1. 清理现有依赖缓存

  • 终端进入项目的ios目录
  • 删除Podfile.lock、Pods文件夹和Runner.xcworkspace文件
  • 回到项目根目录,执行:
    flutter clean
    flutter pub get
    

2. 修改Podfile配置

移除Podfile中手动添加的Firebase Pod行,保留Flutter自动管理依赖的逻辑。修改后的Podfile如下:

platform :ios, '13.0'
workspace 'Runner/Workspace.xcworkspace'

# 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__))

  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)
    target.build_configurations.each do |config|
      config.build_settings['EXCLUDED_ARCHS[sdk=iphonesimulator*]'] = 'arm64'
    end
  end
end

3. 重新安装Pods

  • 回到ios目录,执行:
    pod install
    
  • 后续务必用Runner.xcworkspace打开Xcode项目,不要直接打开Runner.xcodeproj

4. 额外检查项

  • 确认项目根目录的pubspec.yaml中已正确添加以下依赖(版本号可根据实际情况调整):
    dependencies:
      flutter:
        sdk: flutter
      firebase_core: ^2.20.0
      firebase_analytics: ^10.5.0
      firebase_messaging: ^14.6.0
    
  • 在Xcode中执行Product -> Clean Build Folder清理构建缓存后再重新构建

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.16 08:55:03