簡體   English   中英

使用RealmSearchView時出現Android DuplicateFileException

[英]Android DuplicateFileException when using RealmSearchView

我正在嘗試實現RealmSearchView( 在此處鏈接 )。 但是問題是,當我將其添加到依賴項時,出現以下錯誤:

    Error:Execution failed for task ':app:transformNative_libsWithMergeJniLibsForDebug'.
> com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK lib/x86/librealm-jni.so
    File1: C:\Users\Username\.gradle\caches\modules-2\files-2.1\io.realm\realm-android\0.82.2\c6325383149a08e5cb668bdc4d3c790708636e47\realm-android-0.82.2.jar
    File2: D:\MyApp\AppName\app\build\intermediates\exploded-aar\io.realm\realm-android-library\2.2.1\jni

我的依賴關系如下:

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:24.2.1'
    compile 'com.google.android.gms:play-services:9.8.0'
    compile 'com.facebook.android:facebook-android-sdk:[4,5)'
    compile 'com.google.firebase:firebase-core:9.8.0'
    compile 'com.google.firebase:firebase-messaging:9.8.0'
    compile 'com.android.support:design:24.2.1'
    compile 'com.github.thorbenprimke:realm-searchview:0.9.1' 
    compile 'com.jakewharton:butterknife:8.4.0'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0'
    testCompile 'junit:junit:4.12'
}

要添加Realm,我遵循了他們的教程( 在此處 ),並且還遵循了RealmSearchView教程( 在此處 )進行添加。 但是它們似乎有沖突嗎?

如何在項目中同時包含這兩者,但又沒有創建這些重復文件?

編輯:這是我添加使其運行的內容:

packagingOptions {
        pickFirst 'lib/x86/librealm-jni.so'
        pickFirst 'lib/arm64-v8a/librealm-jni.so'
        pickFirst 'lib/armeabi-v7a/librealm-jni.so'
        pickFirst 'lib/mips/librealm-jni.so'
    }

但是,現在出現此錯誤(現在使用的是錯誤的Realm版本嗎?)

E/UncaughtException: java.lang.NoSuchMethodError: No static method init(Landroid/content/Context;)V in class Lio/realm/Realm; or its super classes (declaration of 'io.realm.Realm' appears in /data/data/uk.tether.topcom.tether/files/instant-run/dex/slice-realm-android-0.82.2_f252e1b50f018c2840011d6a94a195daa3c99f49-classes.dex)
                                                                                    at uk.abc.def.ghi.RealmUtilities.RealmManagement.intialiseRealmDatabase(RealmManagement.java:20)
                                                                                    at uk.abc.def.ghi.SplashScreenActivity.onCreate(SplashScreenActivity.java:63)
                                                                                    at android.app.Activity.performCreate(Activity.java:5958)
                                                                                    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1129)
                                                                                    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2364)
                                                                                    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2474)
                                                                                    at android.app.ActivityThread.access$800(ActivityThread.java:144)
                                                                                    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1359)
                                                                                    at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                                    at android.os.Looper.loop(Looper.java:155)
                                                                                    at android.app.ActivityThread.main(ActivityThread.java:5696)
                                                                                    at java.lang.reflect.Method.invoke(Native Method)
                                                                                    at java.lang.reflect.Method.invoke(Method.java:372)
                                                                                    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1028)
                                                                                    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)

這打破了'init'方法的調用:

public void intialiseRealmDatabase(Context context){
        Realm.init(context);
    }

編輯2:原來在Realm搜索控制器教程( 此處 )中使用的RealmSearchView版本已過時。 應該是0.9.6版!

compile 'com.github.thorbenprimke:realm-searchview:0.9.1'依賴項引用了Realm版本0.82.2,同時還包括Realm 2.1。

您應該將依賴項放到realm-searchview因為它已經過期,或者您需要復制存儲庫並自己進行更新,然后手動將其添加到項目中。

或者,如果它支持最新的Realm版本,則只需將其更新為較新的版本。

packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/ASL2.0'
        pickFirst 'lib/x86/librealm-jni.so'

    }

在gradle文件中使用此行將對您有所幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM