【Androidstudio】More than one file was found with OS independent path 'META-INF/androidx.legacy_le...

一、问题描述

com.android.builder.merge.DuplicateRelativeFileException: More than one file was found with OS independent path 'META-INF/androidx.legacy_legacy-support-core-utils.version'
    at com.android.builder.merge.StreamMergeAlgorithms.lambda$acceptOnlyOne$2(StreamMergeAlgorithms.java:75)
    at com.android.builder.merge.StreamMergeAlgorithms.lambda$select$3(StreamMergeAlgorithms.java:100)
    at com.android.builder.merge.IncrementalFileMergerOutputs$1.update(IncrementalFileMergerOutputs.java:102)
    at com.android.builder.merge.DelegateIncrementalFileMergerOutput.update(DelegateIncrementalFileMergerOutput.java:69)
    at com.android.build.gradle.internal.transforms.MergeJavaResourcesTransform$1.update(MergeJavaResourcesTransform.java:387)
    at com.android.builder.merge.IncrementalFileMerger.updateChangedFile(IncrementalFileMerger.java:225)
    at com.android.builder.merge.IncrementalFileMerger.mergeChangedInputs(IncrementalFileMerger.java:190)
    at com.android.builder.merge.IncrementalFileMerger.merge(IncrementalFileMerger.java:77)
    at com.android.build.gradle.internal.transforms.MergeJavaResourcesTransform.transform(MergeJavaResourcesTransform.java:411)
    at com.android.build.gradle.internal.pipeline.TransformTask$2.call(TransformTask.java:222)
    at com.android.build.gradle.internal.pipeline.TransformTask$2.call(TransformTask.java:218)
    at com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:102)
    at com.android.build.gradle.internal.pipeline.TransformTask.transform(TransformTask.java:213)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
....

二、问题原因

是因为一个文件在jar包中出现多次,也就是是android.support和androidx不能共存,而我们在dependencies就出现两个公用的情形。所以检测项目的build.gradle文件中的dependencies,如下:

implementation 'androidx.recyclerview:recyclerview:1.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'

三、解决方法

1、根本解决问题方法·1:(亲测可用) 删除掉android.support库即可。
2、解决问题方法2:(未测试)
需要在app.gradle文件里面android节点下添加这样的代码

【Androidstudio】More than one file was found with OS independent path 'META-INF/androidx.legacy_le..._第1张图片
image.png

packagingOptions {      
 exclude 'META-INF/LGPL2.1'      
 exclude 'META-INF/LICENSE'       
 exclude 'META-INF/NOTICE'        
 exclude 'META-INF/androidx.legacy_legacy-support-core-utils.version'       
 exclude 'META-INF/androidx.loader_loader.version'    
}

你可能感兴趣的:(【Androidstudio】More than one file was found with OS independent path 'META-INF/androidx.legacy_le...)