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

Flutter 3.19.X升级后Firebase Analytics配置异常求助

修复Flutter 3.19中Firebase Analytics的"Missing google_app_id"问题

一、Android端配置排查与修复

  • 先检查google-services.json是否放在android/app目录下,且是对应Firebase项目的最新文件,别用错其他项目的配置文件。
  • 核对gradle配置:
    • 项目根目录的android/build.gradle里,必须添加google-services插件依赖:
      buildscript {
          dependencies {
              // 版本建议用最新稳定版,和Firebase SDK匹配即可
              classpath 'com.google.gms:google-services:4.4.1'
          }
      }
      
    • android/app/build.gradle末尾必须应用插件,否则配置不生效:
      apply plugin: 'com.google.gms.google-services'
      
    • android/settings.gradle里要包含google和mavenCentral仓库,正确配置如下:
      pluginManagement {
          repositories {
              google()
              mavenCentral()
              gradlePluginPortal()
          }
      }
      dependencyResolutionManagement {
          repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
          repositories {
              google()
              mavenCentral()
          }
      }
      
  • 清理缓存后重新构建:执行flutter clean,删除android/.gradle目录,再运行flutter build apk。

二、iOS端配置排查与修复

  • 确认GoogleService-Info.plist是通过Xcode添加到项目中的,且在Target的Build Phases -> Copy Bundle Resources列表里能找到该文件,避免手动拖拽后未加入资源列表。
  • 检查Podfile配置:
    • 确保platform版本不低于iOS 11.0(Firebase当前最低要求版本)
    • 执行pod install --repo-update更新所有依赖,避免使用旧缓存的pod包。
  • 清理iOS缓存:删除Pods目录、Podfile.lock,执行pod deintegrate,再重新运行pod install。

三、Flutter Firebase依赖检查

  • pubspec.yaml里的firebase_core和firebase_analytics版本要与Flutter 3.19兼容,直接使用最新稳定版即可:
    dependencies:
      firebase_core: ^2.24.2
      firebase_analytics: ^10.7.2
    
  • 执行flutter pub get更新依赖包。

四、额外排查点

  • 核对Firebase项目中的Android包名、iOS Bundle ID与应用的完全一致,字符拼写、大小写都不能错。
  • 确保在使用Analytics功能前,已经调用了await Firebase.initializeApp(),这是Firebase初始化的必要步骤。
  • Android端无需额外添加权限,Firebase会自动在Manifest中添加INTERNET等必要权限,但可以确认是否被误删除。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.28 06:02:40