Firebase API初始化失败.java.lang.reflect.InvocationTargetException

时间:2018-03-01 10:27:31

标签: android firebase firebase-realtime-database push-notification firebase-cloud-messaging

我已将FCM数据库集成到我的Android项目中。我用它来聊天应用程序。现在我需要使用FireBase实现云消息(推送通知)。实施FCM后,我收到错误 -

  

Firebase API初始化失败。 java.lang.reflect.InvocationTargetException

我发送gradle脚本请看看。

模块: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 个答案:

答案 0 :(得分:3)

要解决此问题,您需要添加以下代码行:

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

作为build.gradle (Project: ProjectName)文件中的最后一行。

如果您还使用身份验证,请同样使用以下代码:

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

我还强烈建议您使用Firebase依赖项的最新版本。最新版本现在是:11.8.0

Google Play服务的最新版本是:

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