2017-09-02 57 views
-1

從Firebase數據庫獲取參考時,應用程序崩潰。以下是我的代碼。Android Firebase數據庫java.lang.NoSuchMethodError:沒有直接方法<init>

該行添加在我的應用程序的build.gradle文件

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

添加了此行的應用類

FirebaseDatabase.getInstance().setPersistenceEnabled(true); 

此線在我的活動的onCreate()

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

my 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:[email protected]' 
    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) 
+0

發佈您的build.gradle文件 –

+0

@Divyesh Patel添加了build.gradle。 –

+0

在gradle文件中加入'compile'c​​om.firebaseui:firebase-ui-database:1.1.1'' –

回答

0

UPDATE 下面是我使用我的應用程序的火力地堡的依賴關係:

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' 

請嘗試使用 這個。希望它可以幫助你。

+0

也試過了。沒有運氣。 –

+0

我不知道爲什麼,但嘗試添加:compile'c​​om.google.android.gms:play-services-auth:11.0.4'。我忘了在答案中提到。 – AndiM

+0

沒有它沒有工作。 –

0

嘗試從工具 - > Android-> SDK管理器更新您的構建工具,而不是更新到它將工作的最新構建工具!

+0

沒有它沒有工作。 –

相關問題