Android Firebase database java.lang.NoSuchMethodError: no direct method <init>



应用程序从firebase数据库获取参考时会崩溃。以下是我的代码。

在我的应用程序build.gradle文件

中添加了此行
   compile 'com.google.firebase:firebase-database:11.0.4'

在应用程序类中添加了此行

   FirebaseDatabase.getInstance().setPersistenceEnabled(true);

在我的活动中添加了此行()

   if(mDatabase == null) {
        mDatabase = FirebaseDatabase.getInstance();
        mStatus = mDatabase.getReference("status"); //App crashes in this line
    }

我的build.gradle

apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
    buildConfigField "String", "BASE_URL", ""baseurl""
    applicationId "com.mydomain"
    minSdkVersion 14
    targetSdkVersion 25
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    jackOptions {
        enabled true
    }
    // Enabling multidex support.
    multiDexEnabled true
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}
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.google.android.gms:play-services-maps:11.0.4'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.android.support:design:25.3.1'
    compile 'com.squareup.retrofit2:retrofit:2.1.0'
    compile 'com.squareup.retrofit2:converter-gson:2.1.0'
    compile 'com.google.android.gms:play-services-location:11.0.4'
    compile 'com.android.support:cardview-v7:25.3.1'
    compile 'io.reactivex.rxjava2:rxjava:2.1.1'
    compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
    compile 'com.tbruyelle.rxpermissions2:rxpermissions:0.9.4@aar'
    compile 'com.squareup.okhttp3:logging-interceptor:3.3.1'
    compile 'com.google.firebase:firebase-database:11.0.4'
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:multidex:1.0.1'
}
apply plugin: 'com.google.gms.google-services'

错误日志

ava.lang.NoSuchMethodError: No direct method <init>(Lcom/google/android/gms/internal/ol;Lcom/google/android/gms/internal/wn;Ljava/util/List;ZLjava/lang/String;Ljava/lang/String;)V in class Lcom/google/firebase/database/connection/idl/zzc; or its super classes (declaration of 'com.google.firebase.database.connection.idl.zzc' appears in /data/app/com.mydomain-1/base.apk)
                                                              at com.google.android.gms.internal.mx.zza(Unknown Source)
                                                              at com.google.android.gms.internal.qd.zza(Unknown Source)
                                                              at com.google.android.gms.internal.qu.<init>(Unknown Source)
                                                              at com.google.android.gms.internal.ry.zzb(Unknown Source)
                                                              at com.google.android.gms.internal.ry.zza(Unknown Source)
                                                              at com.google.firebase.database.FirebaseDatabase.zzFm(Unknown Source)
                                                              at com.google.firebase.database.FirebaseDatabase.getReference(Unknown Source)
                                                              at com.mydomain.Ui.SplashActivity$3.onResponse(SplashActivity.java:115)
                                                              at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall$1$1.run(ExecutorCallAdapterFactory.java:68)
                                                              at android.os.Handler.handleCallback(Handler.java:815)
                                                              at android.os.Handler.dispatchMessage(Handler.java:104)
                                                              at android.os.Looper.loop(Looper.java:207)
                                                              at android.app.ActivityThread.main(ActivityThread.java:5776)
                                                              at java.lang.reflect.Method.invoke(Native Method)
                                                              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
                                                              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)

update 这是我用于应用程序的firebase的依赖性:

compile 'com.google.firebase:firebase-core:10.2.0'
compile 'com.google.firebase:firebase-auth:10.2.0'
compile 'com.google.android.gms:play-services-auth:10.2.0'
compile 'com.google.firebase:firebase-database:10.2.0'
compile 'com.google.firebase:firebase-messaging:10.2.0'

我认为您需要再添加一个依赖性,即:

compile 'com.google.firebase:firebase-core:11.0.4'

请尝试使用此。希望它对您有帮助。

尝试从工具 -> android-> sdk管理器更新构建工具,而不是更新到最新的构建工具!

相关内容

最新更新