在使用 Google Analytics 和 Flutter 时,获取
缺少 google_app_id。 Firebase 分析已禁用。请参阅“https://goo .gl/NAOOOI”
我尝试了很多方法,但这个问题仍然没有消失。我用过
"apply plugin: 'com.google.gms.google-services'"
也在我的 android.build.gradle 文件中。
编辑:
以下说明不再可用,因为它们已替换为 https://firebase.google.com/docs/auth/flutter/start,它使用
flutterfire configure
命令自动添加所需的依赖项。
您是否还按照说明添加了类路径和实现部分?
我的项目使用旧版本的 flutter admob 插件和
google-services.json
文件。新的 Admob 插件期望 json 文件中存在 admob_app_id
键值对。
我通过下载新的
google-services.json
文件并用新下载的文件替换旧文件解决了这个问题。
如果您使用 flutterfire_cli 配置了 firebase,则每次向项目添加新包时都需要进行配置
flutter pub 添加 firebase_analytics
flutterfire 配置
我刚刚在 Firebase 控制台中打开分析仪表板,以确保它没有被禁用,发现一切正常,之后我停止了应用程序并重新运行,发现错误消失了。
自 Flutter 3.16.4 起,所有新应用程序上的 Gradle 设置默认已更改,导致破坏了 flutter-fire CLI 自动配置。
您必须自己配置Android gradle。
这对我有用。
./android/settings.gradle
plugins {
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
id "com.android.application" version "7.3.0" apply false
id "org.jetbrains.kotlin.android" version "1.9.0" apply false
id "com.google.gms.google-services" version "4.3.15" apply false
id "com.google.firebase.crashlytics" version "2.8.1" apply false
id "com.google.firebase.firebase-perf" version "1.4.2" apply false
}
注意:版本可能已经过时,要么是这篇文章太旧,要么是与其他版本不兼容。例如:firebase-perf (1.4.2) 仅与 google-services:4.3.15 和 kotlin (1.9.0) 兼容
./android/app/build.gradle
plugins {
id "com.android.application"
id "kotlin-android"
id "dev.flutter.flutter-gradle-plugin"
id "com.google.gms.google-services"
id 'com.google.firebase.crashlytics'
id 'com.google.firebase.firebase-perf'
}
android {
...
compileSdk 34
...
defaultConfig {
...
minSdkVersion 28
targetSdkVersion 34
...
}
...
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.9.0"
implementation(platform("com.google.firebase:firebase-bom:32.8.0"))
implementation("com.google.firebase:firebase-analytics")
implementation("com.google.firebase:firebase-crashlytics")
implementation("com.google.firebase:firebase-perf")
}
./android/app/src/main/AndroidManifest.xml
<application>
....
<meta-data
android:name="firebase_performance_logcat_enabled"
android:value="true" />
....
</application>