2017-08-27 62 views
0

我已經將Realm包含在一個項目中,並且遵循了文檔。但每當我編譯和運行應用程序,我得到以下錯誤:java.lang.NoSuchMethodError:使用領域數據庫時,找不到方法

FATAL EXCEPTION: main 
     Process: org.innoversetech.wifinity, PID: 8391 
     java.lang.NoSuchMethodError: No static method loadLibrary(Landroid/content/Context;Ljava/lang/String;Ljava/lang/String;)V in class Lcom/getkeepsafe/relinker/ReLinker; or its super classes (declaration of 'com.getkeepsafe.relinker.ReLinker' appears in /data/app/org.innoversetech.wifinity-2/split_lib_dependencies_apk.apk:classes16.dex) 
     at io.realm.internal.RealmCore.loadLibrary(RealmCore.java:60) 
     at io.realm.Realm.init(Realm.java:200) 
     at org.innoversetech.wifinity.MyApplication.onCreate(MyApplication.java:17) 
     at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1037) 
     at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6496) 
     at android.app.ActivityThread.access$1800(ActivityThread.java:229) 
     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1887) 
     at android.os.Handler.dispatchMessage(Handler.java:102) 
     at android.os.Looper.loop(Looper.java:148) 
     at android.app.ActivityThread.main(ActivityThread.java:7406) 
     at java.lang.reflect.Method.invoke(Native Method) 
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) 
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 

我一直在這幾個小時了,我不明白是什麼問題。這裏是我的MyApplication的類代碼:

import android.app.Application; 

import io.realm.Realm; 
import io.realm.RealmConfiguration; 

public class MyApplication extends Application { 

    @Override 
    public void onCreate() { 

     super.onCreate(); 
     Realm.init(getApplicationContext()); 
     RealmConfiguration realmConfiguration = new RealmConfiguration.Builder() 
       .name(Realm.DEFAULT_REALM_NAME) 
       .schemaVersion(0) 
       .deleteRealmIfMigrationNeeded() 
       .build(); 
     Realm.setDefaultConfiguration(realmConfiguration); 

    } 
} 

這是我的應用程序級的build.gradle:

apply plugin: 'com.android.application' 
apply plugin: 'realm-android' 
repositories { 
    maven { 
     url "https://jitpack.io" 
    } 
} 
android { 
    compileSdkVersion 25 
    buildToolsVersion "25.0.2" 
    defaultConfig { 
     applicationId "org.innoversetech.wifinity" 
     minSdkVersion 18 
     targetSdkVersion 25 
     versionCode 1 
     versionName "1.0" 
     testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 
     vectorDrawables.useSupportLibrary = true 

    } 
    buildTypes { 
     release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 
     debug { 
      proguardFile 'D:/Code/Android/KillMe/Wifinity/app/proguard-rules.pro' 
     } 
    } 
} 

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' 
    }) 
    //dependencies 
    compile('com.mikepenz:materialdrawer:[email protected]') { 
     transitive = true 
    } 
    compile 'devlight.io:navigationtabbar:1.2.5' 
    compile 'devlight.io:navigationtabbar:1.2.5' 
    compile 'com.android.support:appcompat-v7:25.3.1' 
    compile 'com.android.support.constraint:constraint-layout:1.0.2' 
    compile 'com.google.code.gson:gson:2.6.2' 
    compile 'com.squareup.retrofit2:retrofit:2.0.2' 
    compile 'com.squareup.retrofit2:converter-gson:2.0.2' 
    compile 'com.android.support:design:25.3.1' 
    compile 'com.android.support:support-vector-drawable:25.3.1' 
    compile 'com.github.florent37:materialviewpager:1.2.1' 
    compile 'com.flaviofaria:kenburnsview:1.0.7' 
    compile 'com.jpardogo.materialtabstrip:library:1.1.0' 
    compile 'com.github.bumptech.glide:glide:3.7.0' 
    compile 'com.jakewharton:butterknife:8.6.0' 
    compile 'com.android.support:recyclerview-v7:25.3.1' 
    compile 'com.android.support:cardview-v7:23.3.0' 
    compile 'com.squareup.picasso:picasso:2.5.2' 
    compile 'com.mani:ThinDownloadManager:1.3.0' 
    compile 'com.github.barteksc:android-pdf-viewer:2.6.1' 
    compile 'com.android.support:support-v4:25.3.1' 
    compile 'com.afollestad.material-dialogs:core:0.9.4.5' 
    compile 'com.afollestad.material-dialogs:commons:0.9.4.5' 
    compile 'com.felipecsl.asymmetricgridview:library:2.0.1' 
    compile 'com.race604.waveloading:library:1.1.1' 
    compile 'com.github.Yalantis:GuillotineMenu-Android:1.2' 
    compile 'net.steamcrafted:materialiconlib:1.1.3' 
    compile 'com.mikepenz:google-material-typeface:[email protected]' 
    compile 'com.mikepenz:fontawesome-typeface:[email protected]' 
    compile 'com.diegodobelo.expandingview:expanding-view:0.9.4' 
    compile 'com.github.thorbenprimke:realm-recyclerview:0.9.25' 
    compile 'it.sephiroth.android.library.targettooltip:target-tooltip-library:1.3.15' 
    compile 'com.getkeepsafe.relinker:relinker:1.2.2' 
    compile 'com.github.KeepSafe:ReLinker:1.1' 
    testCompile 'junit:junit:4.12' 
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.6.0' 
} 
configurations.all { 
    resolutionStrategy.eachDependency { DependencyResolveDetails details -> 
     def requested = details.requested 
     if (requested.group == 'com.android.support') { 
      if (!requested.name.startsWith("multidex")) { 
       details.useVersion '26.0.0-alpha1' 
      } 
     } 
    } 

} 

這是該項目的gradle級別:

// Top-level build file where you can add configuration options common to all sub-projects/modules. 

buildscript { 
    repositories { 
     jcenter() 
     maven{ 
      url "https://jitpack.io" 
     } 
    } 
    dependencies { 
     classpath 'com.android.tools.build:gradle:2.3.3' 
     classpath "io.realm:realm-gradle-plugin:3.5.0" 

     // NOTE: Do not place your application dependencies here; they belong 
     // in the individual module build.gradle files 
    } 
} 


allprojects { 
    repositories { 
     jcenter() 
    } 
} 

task clean(type: Delete) { 
    delete rootProject.buildDir 
} 

這是當我刪除ReLinker庫時出現錯誤:

Process: org.innoversetech.wifinity, PID: 22788 
    java.lang.NoClassDefFoundError: Failed resolution of: Lcom/getkeepsafe/relinker/ReLinker; 
     at io.realm.internal.RealmCore.loadLibrary(RealmCore.java:60) 
     at io.realm.Realm.init(Realm.java:200) 
     at org.innoversetech.wifinity.MyApplication.onCreate(MyApplication.java:17) 
     at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1037) 
     at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6496) 
     at android.app.ActivityThread.access$1800(ActivityThread.java:229) 
     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1887) 
     at android.os.Handler.dispatchMessage(Handler.java:102) 
     at android.os.Looper.loop(Looper.java:148) 
     at android.app.ActivityThread.main(ActivityThread.java:7406) 
     at java.lang.reflect.Method.invoke(Native Method) 
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) 
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 
    Caused by: java.lang.ClassNotFoundException: Didn't find class "com.getkeepsafe.relinker.ReLinker" on path: DexPathList[[zip file "/data/app/org.innoversetech.wifinity-1/base.apk", zip file "/data/app/org.innoversetech.wifinity-1/split_lib_dependencies_apk.apk", zip file "/data/app/org.innoversetech.wifinity-1/split_lib_slice_0_apk.apk", zip file "/data/app/org.innoversetech.wifinity-1/split_lib_slice_1_apk.apk", zip file "/data/app/org.innoversetech.wifinity-1/split_lib_slice_2_apk.apk", zip file "/data/app/org.innoversetech.wifinity-1/split_lib_slice_3_apk.apk", zip file "/data/app/org.innoversetech.wifinity-1/split_lib_slice_4_apk.apk", zip file "/data/app/org.innoversetech.wifinity-1/split_lib_slice_5_apk.apk", zip file "/data/app/org.innoversetech.wifinity-1/split_lib_slice_6_apk.apk", zip file "/data/app/org.innoversetech.wifinity-1/split_lib_slice_7_apk.apk", zip file "/data/app/org.innoversetech.wifinity-1/split_lib_slice_8_apk.apk", zip file "/data/app/org.innoversetech.wifinity-1/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/org.innoversetech.wifinity-1/lib/arm, /data/app/org.innoversetech.wifinity-1/base.apk!/lib/armeabi-v7a, /data/app/org.innoversetech.wifinity-1/split_lib_dependencies_apk.apk!/lib/armeabi-v7a, /data/app/org.innoversetech.wifinity-1/split_lib_slice_0_apk.apk!/lib/armeabi-v7a, /data/app/org.innoversetech.wifinity-1/split_lib_slice_1_apk.apk!/lib/armeabi-v7a, /data/app/org.innoversetech.wifinity-1/split_lib_slice_2_apk.apk!/lib/armeabi-v7a, /data/app/org.innoversetech.wifinity-1/split_lib_slice_3_apk.apk!/lib/armeabi-v7a, /data/app/org.innoversetech.wifinity-1/split_lib_slice_4_apk.apk!/lib/armeabi-v7a, /data/app/org.innoversetech.wifinity-1/split_lib_slice_5_apk.apk!/lib/armeabi-v7a, /data/app/org.innoversetech.wifinity-1/split_lib_slice_6_apk.apk!/lib/armeabi-v7a, /data/app/org.innoversetech.wifinity-1/split_lib_slice_7_apk.apk!/lib/armeabi-v7a, /data/app/org.innoversetech.wifinity-1/split_lib_slice_8_apk.apk!/lib/armeabi-v7a, /data/app/org.innoversetech.wifinity-1/split_lib_slice_9_apk.apk!/lib/armeabi-v7a, /vendor/lib, /system/lib]] 
     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56) 
     at java.lang.ClassLoader.loadClass(ClassLoader.java:511) 
     at java.lang.ClassLoader.loadClass(ClassLoader.java:469) 
     at io.realm.internal.RealmCore.loadLibrary(RealmCore.java:60)  
     at io.realm.Realm.init(Realm.java:200)  
     at org.innoversetech.wifinity.MyApplication.onCreate(MyApplication.java:17)  
     at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1037)  
     at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6496)  
     at android.app.ActivityThread.access$1800(ActivityThread.java:229)  
     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1887)  
     at android.os.Handler.dispatchMessage(Handler.java:102)  
     at android.os.Looper.loop(Looper.java:148)  
     at android.app.ActivityThread.main(ActivityThread.java:7406)  
     at java.lang.reflect.Method.invoke(Native Method)  
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)  
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)  
     Suppressed: java.lang.ClassNotFoundException: com.getkeepsafe.relinker.ReLinker 
     at java.lang.Class.classForName(Native Method) 
     at java.lang.BootClassLoader.findClass(ClassLoader.java:781) 
     at java.lang.BootClassLoader.loadClass(ClassLoader.java:841) 
     at java.lang.ClassLoader.loadClass(ClassLoader.java:504) 
       ... 14 more 
    Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available 
+0

該錯誤可能來自境界......但錯誤的是你給其他庫'com.getkeepsafe.relinker' –

+0

我應該刪除嗎?然後我得到另一個錯誤 –

+0

例如,您有衝突的庫...'com.github.KeepSafe:ReLinker:1.1',並且該方法可能不存在於該版本中 –

回答

0

境界取決於implementation 'com.getkeepsafe.relinker:relinker:1.2.2'(基本上是「編譯」),但我覺得你的問題是由

compile 'com.github.thorbenprimke:realm-recyclerview:0.9.25' 

造成的,因爲版本0.9.25的境界版本2.2.1帶來的,這樣就可以防止衝突的境界3.5.0 。

一個可能的解決方案是將RealmBasedRecyclerViewAdapter的來源複製到您的代碼,以便它不依賴於舊的東西。

你可以做的另一件事就是不使用RealmBasedRecyclerViewAdapter,並嘗試在realm-android-adapters

乾淨+重建可能也有幫助。

在你的onCreate使用
0

realmConfiguration = new RealmConfiguration.Builder().build(); 
realm = Realm.getInstance(realmConfiguration);