Why Do I Get “Multiple dex files define Landroid/support/v7/recyclerview/extensions/ListAdapter”

[亡魂溺海] 提交于 2019-11-28 08:16:55

问题


I get the dreaded java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex error. The stack trace shows the root cause as:

Caused by: com.android.dex.DexException: Multiple dex files define Landroid/support/v7/recyclerview/extensions/ListAdapter;
        at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:661)
        at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:616)
        at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:598)
        at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
        at com.android.dx.merge.DexMerger.merge(DexMerger.java:198)
        at com.android.builder.dexing.DexArchiveMergerCallable.call(DexArchiveMergerCallable.java:61)

What is the root cause?


回答1:


Most likely, you are attempting to use these two dependencies:

implementation "android.arch.paging:runtime:1.0.0-alpha5"
implementation "com.android.support:recyclerview-v7:27.1.0"

The conflicting class (android.support.v7.recyclerview.extensions.ListAdapter) moved to recyclerview-v7 from the Paging runtime... but only with 1.0.0-alpha6 or higher of the Paging runtime. With 1.0.0-alpha5, coupled with 27.1.0 of the Support Library, you get the same class in both places.

Instead, migrate to:

implementation "android.arch.paging:runtime:1.0.0-alpha6"
implementation "com.android.support:recyclerview-v7:27.1.0"



回答2:


I had a similar but different error message, and there seems no other suspicious gradle dependencies which may collide with implementation 'com.android.support:recyclerview-v7:28.0.0'

Multiple dex files define Landroid/support/v7/widget/DefaultItemAnimator$6;

Finnally, I found that there was already a file android-support-v7-recyclerview.jar existing in the lib directory of this project.

Remove this file and sync with gradle, then everything went fine



来源:https://stackoverflow.com/questions/49076888/why-do-i-get-multiple-dex-files-define-landroid-support-v7-recyclerview-extensi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!