I am using multiple firebase projects in an Android App. I am getting this error : Missing google_app_id. Firebase Analytics disabled
Asked Answered
C

7

19

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.

I have cross checked the ids from google-services.json files of all the projects. 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.

Cow answered 21/3, 2017 at 12:4 Comment(4)
redownload the google-services.json again and rebuild your projectDonley
I did that. It is not working !Cow
The docs say "Note: On Android and iOS, Firebase Analytics are only logged for the default app." firebase.google.com/docs/configure, have you check that?Prophecy
@Cow Have you found a solution for this issue?Unreasoning
P
6

Could you double check if google-services.json is located at your Android app module root directory?

enter image description here

If it is there, make sure google-services.json has the mobilesdk_app_id key. It should be located under the client_info node.

 {
   ...,
   "client": [
     {
        "client_info": {
          "mobilesdk_app_id": "random_string",
          ...
        }
     }
   ]
 }
Proof answered 21/3, 2017 at 21:50 Comment(2)
Yes. I cross checked it again. It is in the proper location and "mobilesdk_app_id":"VALUE" is also there.Cow
The main problem was I wanted to initialise the default firebase project programmatically. I have to use at least one google-services.json file to initialise the default project. Here is how the firebase initialises itself : How does Firebase initialize on Android?.Cow
G
36

In my case the problem was with incomplete Firebase configuration.

I was missing

buildscript {
    ...
    dependencies {
        ...
        classpath 'com.google.gms:google-services:4.3.3' // google-services plugin
    }
}

allprojects {
    ...
    repositories {
        google()
    }
}

from build.gradle.

And

// ADD THIS AT THE BOTTOM
apply plugin: 'com.google.gms.google-services'

from app/build.gradle.

Gatepost answered 21/9, 2018 at 16:0 Comment(2)
Thanks! // ADD THIS AT THE BOTTOM also works at the top. Fixed it for me.Eldoneldora
Adding this solve my connection issue too. I am looking at the FlutterFire tutorial on the setup, but do no realize I need to update the Android project too. It seems FlutterFire CLI didn't help me to auto add this line and the tutorial didn't emphasis me to add back this lines.Trichomonad
P
6

Could you double check if google-services.json is located at your Android app module root directory?

enter image description here

If it is there, make sure google-services.json has the mobilesdk_app_id key. It should be located under the client_info node.

 {
   ...,
   "client": [
     {
        "client_info": {
          "mobilesdk_app_id": "random_string",
          ...
        }
     }
   ]
 }
Proof answered 21/3, 2017 at 21:50 Comment(2)
Yes. I cross checked it again. It is in the proper location and "mobilesdk_app_id":"VALUE" is also there.Cow
The main problem was I wanted to initialise the default firebase project programmatically. I have to use at least one google-services.json file to initialise the default project. Here is how the firebase initialises itself : How does Firebase initialize on Android?.Cow
E
5

The issue could be due to instant app being enabled

Solution : Manually add google_app_id to the strings.xml file — as told here

enter image description here

Update : In case app crashes without any warning or error, try this (maven):

Go to project level build.gradle & check if it looks exactly like this:

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.

Eldrid answered 9/2, 2019 at 10:34 Comment(0)
V
1

Initialize FirebaseApp early in OnCreate() using APP ID and Client key:

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

Vidrine answered 31/10, 2018 at 7:1 Comment(1)
you just leaked your API key 🫤Oxa
E
1

@Anton Malyshev 's answer is correct.

    ↓ 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'
Eldoneldora answered 17/5, 2020 at 18:8 Comment(0)
C
1

Manually add google_app_id to the strings.xml file like:

You can get google_app_id from google-services.json, in which it is defined as mobilesdk_app_id.

Certes answered 2/6, 2020 at 15:46 Comment(0)
M
0

For my case I increased the gradle version from
classpath 'com.android.tools.build:gradle:3.4.1' to

classpath 'com.android.tools.build:gradle:4.3.8'

in build.gradle project level and the problem disappeared

Merriemerrielle answered 4/8, 2021 at 13:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.