简体   繁体   English

使用RealmSearchView时出现Android DuplicateFileException

[英]Android DuplicateFileException when using RealmSearchView

I am trying to implement RealmSearchView ( link here ). 我正在尝试实现RealmSearchView( 在此处链接 )。 But the issue is, when I add it to my dependencies I get the following error: 但是问题是,当我将其添加到依赖项时,出现以下错误:

    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

My dependencies look like: 我的依赖关系如下:

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'
}

To add Realm I followed their tutorial ( here ), and I also followed the RealmSearchView tutorial ( here ) to add that. 要添加Realm,我遵循了他们的教程( 在此处 ),并且还遵循了RealmSearchView教程( 在此处 )进行添加。 But they seem to be conflicting? 但是它们似乎有冲突吗?

How can I include both within the project, but without these duplicate files being created? 如何在项目中同时包含这两者,但又没有创建这些重复文件?

EDIT: This is what I have added to get it to run: 编辑:这是我添加使其运行的内容:

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'
    }

However, now I get this error (is it now using the wrong Realm version?) 但是,现在出现此错误(现在使用的是错误的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)

Which breaks the 'init' method call here: 这打破了'init'方法的调用:

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

EDIT 2: Turns out the RealmSearchView version used in the the Realm search controller tutorial ( here ) is out of date. 编辑2:原来在Realm搜索控制器教程( 此处 )中使用的RealmSearchView版本已过时。 It should be version 0.9.6! 应该是0.9.6版!

Your dependency to compile 'com.github.thorbenprimke:realm-searchview:0.9.1' references Realm version 0.82.2, while you also include Realm 2.1. compile 'com.github.thorbenprimke:realm-searchview:0.9.1'依赖项引用了Realm版本0.82.2,同时还包括Realm 2.1。

You should drop the dependency to realm-searchview because it is out of date, or you'll need to copy the repository and update it yourself and manually add it to your project. 您应该将依赖项放到realm-searchview因为它已经过期,或者您需要复制存储库并自己进行更新,然后手动将其添加到项目中。

Or just update it to a newer version, if it supports the latest Realm versions. 或者,如果它支持最新的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'

    }

use this line in your gradle file will help you. 在gradle文件中使用此行将对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM