mark922
mark922

Reputation: 1167

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.

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.

Upvotes: 19

Views: 26608

Answers (7)

J.Ongoma
J.Ongoma

Reputation: 63

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

Upvotes: 0

vids
vids

Reputation: 441

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.

Upvotes: 1

gregn3
gregn3

Reputation: 1774

@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'

Upvotes: 1

Anton Malyshev
Anton Malyshev

Reputation: 8861

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.

Upvotes: 36

Garvit Jain
Garvit Jain

Reputation: 2022

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.

Upvotes: 5

lashgar
lashgar

Reputation: 5470

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

Upvotes: 1

Guilherme Puglia
Guilherme Puglia

Reputation: 179

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",
          ...
        }
     }
   ]
 }

Upvotes: 6

Related Questions