0

I have integrated the FCM Database in my Android project. I used it for chat application. Now I need to implement the cloud message(Push notification) using FireBase. After I implement the FCM, I got an error-

Firebase API initialization failure. java.lang.reflect.InvocationTargetException

I am sending the gradle script please have a look.

Module :app

apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
    applicationId "com.example.swatin.groupchatapplication"
    minSdkVersion 16
    targetSdkVersion 25
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
             }
           }
 }
 repositories {
 mavenCentral()
  maven { url 'https://maven.google.com' }
 }

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
})
compile project(':libbambuser-0.9.12')
compile 'com.basgeekball:awesome-validation:1.3'
compile 'com.android.support:recyclerview-v7:25.3.1'
compile 'com.android.support:cardview-v7:25.1.0'
compile 'com.razorpay:checkout:1.4.1'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.google.firebase:firebase-core:10.0.1'
compile 'com.google.firebase:firebase-messaging:10.0.1'
compile 'com.google.firebase:firebase-auth:10.0.1'
compile 'com.google.firebase:firebase-database:10.0.1'
compile 'com.firebaseui:firebase-ui:2.0.1'
compile 'com.squareup.okhttp:okhttp:2.0.0'
compile 'com.squareup.okhttp3:okhttp:3.7.0'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.github.bumptech.glide:glide:4.3.1'
compile 'com.android.support:support-v4:25.3.1'
compile 'com.android.volley:volley:1.0.0'
compile 'com.android.volley:volley:1.1.0-rc1'
compile 'de.hdodenhof:circleimageview:2.1.0'
compile 'com.paypal.sdk:paypal-android-sdk:2.14.2'

testCompile 'junit:junit:4.12'
annotationProcessor 'com.github.bumptech.glide:compiler:4.3.1'
} 
apply plugin: 'com.google.gms.google-services'

build.gradle (Project: ProjectName)

buildscript {
repositories {
    jcenter()
}
dependencies {
    classpath 'com.android.tools.build:gradle:2.3.3'

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
    classpath 'com.google.gms:google-services:3.0.0'
}
}

allprojects {
repositories {
    jcenter()

}
}

task clean(type: Delete) {
delete rootProject.buildDir
}
1
  • When I changed classpath 'com.google.gms:google-services:3.2.0' to latest 4.2.0 error is gone(Flutter user) Commented May 4, 2019 at 14:28

1 Answer 1

3

To solve this, you need to add the following line of code:

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

As the last line in your build.gradle (Project: ProjectName) file.

And if you are using also authentication, please also this line of code:

compile 'com.google.android.gms:play-services-auth:10.0.1'

I also strongly recommend you to use the latest versions for your Firebase dependencies. The latest version is now: 11.8.0.

The last version for Google Play Services is:

classpath 'com.google.gms:google-services:3.2.0'
Sign up to request clarification or add additional context in comments.

8 Comments

Sorry is it Project: ProjectName or Module :app ?
I change the class path. classpath 'com.google.gms:google-services:3.2.0' but still same error.
Be sure to have the latest and the same versions to all of your dependencies. See also Firebase-UI](github.com/firebase/FirebaseUI-Android) compatibilities.
Yes, update all your depenedencies to the last version.
Hi can you suggest any solution about "Push notification though app is not oppen? Like gmail or Whatsapp"
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.