简体   繁体   English

我在一个 Android 应用程序中使用多个 firebase 项目。 我收到此错误:缺少 google_app_id。 Firebase 分析已停用

[英]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'

Manually add google_app_id to the strings.xml file like:手动将google_app_id添加到strings.xml文件中,例如:

You can get google_app_id from google-services.json , in which it is defined as mobilesdk_app_id .您可以从google-services.json获取google_app_id ,其中定义为mobilesdk_app_id

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.

相关问题 Android Kotlin:缺少 google_app_id。 Firebase 分析已禁用 - Android Kotlin : Missing google_app_id. Firebase Analytics disabled Flutter:缺少 google_app_id。 Firebase 禁用分析 - Flutter: Missing google_app_id. Firebase Analytics disabled 无法使Firebase不适用于非Gradle版本:缺少google_app_id。 Firebase Analytics已禁用 - Unable to make Firebase work for a non Gradle build: Missing google_app_id. Firebase Analytics disabled 我正在尝试将 firebase 云消息连接到 android 应用程序。 应用未加载错误“找不到 com.google.firbase:firebase-core:17.0.1”。 - i am trying to connect firebase cloud messaging to android app. app is not loading the error "Could not find com.google.firbase:firebase-core:17.0.1." 我正在使用 flutter 编写 Firebase 应用程序,但我收到有关 google-services.json 和初始化的错误 - I am coding a Firebase app with flutter but i am getting errors about google-services.json and inititilization Android中使用sinch的来电通知,我正在使用FireBase Messaging服务,但当应用程序在后台被杀死时却无法接听电话 - Incoming call Notification using sinch in Android ,I am Using FireBase Messaging service but not getting calls when app is killed in background Android:我可以在Firebase App中使用Google Analytics(分析) - Android: Can I use Google Analytics with Firebase App 我正在尝试制作一个从 Firebase 搜索文件的应用程序,但出现此错误 - Im trying to make an app that searches files from Firebase and I am getting this error 我是 android 开发的新手。 我正在制作我的第一个应用程序,但出现错误: - I am new to android development. I am making my first app but I am getting an error: 使用Cordova应用中的cordova-plugin-firebase-analytics插件,Android上的google_app_id错误无效 - Invalid google_app_id error on Android with cordova-plugin-firebase-analytics plugin in Cordova app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM