從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)
發佈您的build.gradle文件 –
@Divyesh Patel添加了build.gradle。 –
在gradle文件中加入'compile'com.firebaseui:firebase-ui-database:1.1.1'' –