[英]I am using multiple firebase projects in an Android App. I am getting this error : Missing google_app_id. Firebase Analytics disabled
I have added following code to initialise there projects.我添加了以下代码来初始化那里的项目。
FirebaseOptions options = new FirebaseOptions.Builder()
.setApplicationId("1:129574837465:android:0123456773a52cf4f6") // Required for Analytics.
.setApiKey("iubdeibneh8gzDt7Xn9f-jdjjdjdjdj") // Required for Auth.
.setDatabaseUrl("https://databasename-d7r7.firebaseio.com") // Required for RTDB.
.build();
FirebaseApp.initializeApp(context /* Context */, options, "secondary");
FirebaseOptions options2 = new FirebaseOptions.Builder()
.setApplicationId("1:129574837465:android:0123456773a52cf4f6") // Required for Analytics.
.setApiKey("iubdeibneh8gzDt7Xn9f-jdjjdjdjdj") // Required for Auth.
.setDatabaseUrl("https://databasename2-d7r7.firebaseio.com") // Required for RTDB.
.build();
FirebaseApp.initializeApp(context /* Context */, options2, "secondary2");
FirebaseOptions options3 = new FirebaseOptions.Builder()
.setApplicationId("1:129574837465:android:0123456773a52cf4f6") // Required for Analytics.
.setApiKey("kjdkj-o_3nk4jn4k3kjk23j") // Required for Auth.
.setDatabaseUrl("https://databasename3-d7r7.firebaseio.com") // Required for RTDB.
.build();
FirebaseApp.initializeApp(context /* Context */, options3, "secondary3");
After initialisation my app is running fine.初始化后,我的应用程序运行良好。 I can use FirebaseAuth, and FirebaseRTDB just fine but it is throwing error when it has to access firebase_Application_Id for analytics.我可以使用 FirebaseAuth 和 FirebaseRTDB 就好了,但是当它必须访问 firebase_Application_Id 进行分析时会抛出错误。
I have cross checked the ids from google-services.json files of all the projects.我已经交叉检查了所有项目的 google-services.json 文件中的 ID。 I don't know why but it throws error saying:我不知道为什么,但它抛出错误说:
Missing google_app_id. Firebase Analytics disabled.
I couldn't figure out the root of this error.我无法弄清楚这个错误的根源。
In my case the problem was with incomplete Firebase configuration.就我而言,问题在于 Firebase 配置不完整。
I was missing我失踪了
buildscript {
...
dependencies {
...
classpath 'com.google.gms:google-services:4.3.3' // google-services plugin
}
}
allprojects {
...
repositories {
google()
}
}
from build.gradle.来自 build.gradle。
And和
// ADD THIS AT THE BOTTOM
apply plugin: 'com.google.gms.google-services'
from app/build.gradle.来自 app/build.gradle。
The issue could be due to instant app
being enabled该问题可能是由于启用了instant app
Solution : Manually add google_app_id to the strings.xml file — as told here解决方案:手动将google_app_id添加到strings.xml文件中 — 如此处所述
Update : In case app crashes without any warning or error, try this (maven):更新:如果应用程序在没有任何警告或错误的情况下崩溃,请尝试此操作(maven):
Go to project level build.gradle
& check if it looks exactly like this:转到项目级别build.gradle
并检查它是否完全像这样:
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
}
and the code suddenly works and when you'll look at other answers you will find the same.并且代码突然起作用了,当您查看其他答案时,您会发现相同的答案。
Could you double check if google-services.json is located at your Android app module root directory?您能否仔细检查一下 google-services.json 是否位于您的 Android 应用模块根目录?
If it is there, make sure google-services.json has the mobilesdk_app_id key.如果存在,请确保 google-services.json 具有 mobilesdk_app_id 密钥。 It should be located under the client_info node.它应该位于 client_info 节点下。
{
...,
"client": [
{
"client_info": {
"mobilesdk_app_id": "random_string",
...
}
}
]
}
Initialize FirebaseApp early in OnCreate() using APP ID and Client key:使用 APP ID 和客户端密钥在 OnCreate() 早期初始化 FirebaseApp:
FirebaseOptions options = new FirebaseOptions.Builder()
.setApplicationId("1:530266078999:android:481c4ecf3253701e") // Required for Analytics.
.setApiKey("AIzaSyBRxOyIj5dJkKgAVPXRLYFkdZwh2Xxq51k") // Required for Auth.
.setDatabaseUrl("https://project-1765055333176374514.firebaseio.com/") // Required for RTDB.
.build();
FirebaseApp.initializeApp(this /* Context */, options, "secondary");
Source: https://firebase.googleblog.com/2016/12/working-with-multiple-firebase-projects-in-an-android-app.html来源: https : //firebase.googleblog.com/2016/12/working-with-multiple-firebase-projects-in-an-android-app.html
@Anton Malyshev 's answer is correct. @Anton Malyshev的回答是正确的。
↓ project gradle ↓ 项目梯度
buildscript {
...
dependencies {
...
classpath 'com.google.gms:google-services:4.3.3' // google-services plugin
}
}
allprojects {
...
repositories {
google()
}
}
↓ app gradle ↓ 应用程序渐变
apply plugin: 'com.google.gms.google-services'
For my case I increased the gradle version from对于我的情况,我增加了 gradle 版本classpath 'com.android.tools.build:gradle:3.4.1'
to classpath 'com.android.tools.build:gradle:3.4.1'
到
classpath 'com.android.tools.build:gradle:4.3.8'
in build.gradle project level and the problem disappeared在 build.gradle 项目级别,问题消失
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.