Default FirebaseApp is not initialized

I had this same issue some time ago.

You're trying to get an instance of Firebase without initialize it. Please add this line of code before you try to get an instance of Firebase, in your main function or a FutureBuilder:

FirebaseApp.initializeApp();

Make sure to add to your root-level build.gradle

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

Then, in your module level Gradle file (usually the app/build.gradle), add the 'apply plugin' line at the bottom of the file to enable the Gradle plugin:

apply plugin: 'com.android.application'

android {
  // ...
}

dependencies {
  // ...
  implementation 'com.google.firebase:firebase-core:9.6.1'
  // Getting a "Could not find" error? Make sure you have
  // the latest Google Repository in the Android SDK manager
}

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

As said in documentation. I had exception as in a question above when forgot to add this in my gradle files.


It seems that google-services:4.1.0 has an issue. Either downgrade it to

classpath 'com.google.gms:google-services:4.0.0'

or upgrade it to

classpath 'com.google.gms:google-services:4.2.0'

dependencies {
    classpath 'com.android.tools.build:gradle:3.3.0-alpha08'
    classpath 'com.google.gms:google-services:4.2.0'
    /*classpath 'com.google.gms:google-services:4.1.0' <-- this was the problem */
}

Hope it helps



UPDATE (11th Nov. 2021):


We do not need to call FirebaseApp.initializeApp(this); anywhere manually. and we should not too.

Possibility 1:

It seems that com.google.gms:google-services:4.3.9 has an issue.

We can either UPGRADE it to

classpath 'com.google.gms:google-services:4.3.10'

or DOWNGRADE it to

classpath 'com.google.gms:google-services:4.3.8'

dependencies {
    classpath 'com.android.tools.build:gradle:4.2.2'
    classpath 'com.google.gms:google-services:4.3.9'// <-- this was the problem
}

Possibility 2:

Make sure to add the below line in app/build.gradle file

apply plugin: 'com.google.gms.google-services'

then clean project and run again. It worked for me.

Possibility 3:

I just faced the same issue about it and got an unexpected and strange solution.

From this answer:

I have removed tools:node="replace" and it's working like charm.