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.
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();
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
I was missing the below line in my app/build.gradle file
apply plugin: 'com.google.gms.google-services'
and once clean project and run again. That fixed it for me.
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.
classpath 'com.google.gms:google-services:4.1.0'
has a problem. instead use:
classpath 'com.google.gms:google-services:4.2.0'
First thing you need to add com.google.gms:google-services:x.x.x at root level build.gradle
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.1'
classpath 'com.google.gms:google-services:3.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
After that you need to apply plugin: 'com.google.gms.google-services' at app/build.gradle
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'com.android.support:cardview-v7:25.3.1'
compile 'com.google.android.gms:play-services-gcm:9.8.0'
compile 'com.google.android.gms:play-services-maps:9.8.0'
compile 'com.google.android.gms:play-services-location:9.8.0'
compile 'com.google.firebase:firebase-messaging:9.8.0'
testCompile 'junit:junit:4.12'
}
apply plugin: 'com.google.gms.google-services'
and if still you are getting problem then you need to add
FirebaseApp.initializeApp(this);
just before you are calling
FirebaseInstanceId.getInstance().getToken();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With