com.android.builder.packaging.DuplicateFileException:复制在META-INF / maven / com.fasterxml.jackson.core / jackson-databind / pom.xml中复制的文件

我正在创build一个应用程序,使用RestAPI来获取数据,对于该操作,我正在使用retrofit 2,okhttp3和jackson来parsingjson以进行对象,我的应用程序也使用Firebase Cloud Messaging

当我编译我的代码,它给了我下面的错误,我无法运行它

错误:执行任务':app:transformResourcesWithMergeJavaResForDebug'失败。

com.android.build.api.transform.TransformException:com.android.builder.packaging.DuplicateFileException:在APK META-INF / maven / com.fasterxml.jackson.core / jackson-databind / pom.xml中复制的重复文件File1: /Users/silent/work/silentinfotech/DoorEye/app/libs/jackson-databind-2.7.2.jar File2:/Users/silent/.gradle/caches/modules-2/files-2.1/com.fasterxml.jackson。芯/jackson-数据绑定/ 2.2.2 / 3c8f6018eaa72d43b261181e801e6f8676c16ef6 /jackson-数据绑定-2.2.2.jar

我正在使用Android Studio 2.1.1OS X EI Capitan 10.11.2

某些库添加在项目的libs文件夹中

转换器-jackson-2.0.2.jar

jackson的注解- 2.7.0.jar

jackson核心2.7.2.jar

jackson-数据绑定- 2.7.2.jar

我的build.gradle文件

apply plugin: 'com.android.application' android { compileSdkVersion 23 buildToolsVersion "23.0.2" defaultConfig { applicationId "com.silentinfotech.dooreye" minSdkVersion 17 targetSdkVersion 23 versionCode 1 versionName "1.0" multiDexEnabled true } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } packagingOptions { exclude 'META-INF/LICENSE' exclude 'META-INF/NOTICE' } } dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:23.4.0' // compile 'com.android.support:support-v4:23.4.0' compile 'com.google.firebase:firebase-messaging:9.0.0' compile 'com.firebase:firebase-client-android:2.5.1+' // compile 'com.github.bumptech.glide:glide:3.7.0' compile 'com.squareup.retrofit2:retrofit:2.0.2' compile 'com.squareup.okhttp3:okhttp:3.2.0' compile 'com.squareup.okhttp3:logging-interceptor:3.0.1' } apply plugin: 'com.google.gms.google-services' 

我也尝试添加以下在我的build.gradle文件,但它不适合我

  packagingOptions { exclude 'META-INF/LICENSE' exclude 'META-INF/NOTICE' } 

也尝试无效的caching和重新启动,也重build,干净,甚至我试图手动删除caching但仍然给我错误

我在我的项目中使用Firebase云消息传递时,我删除了Firebase云消息传递的所有依赖项,然后项目成功运行,但是当我添加FCM依赖性时,它总是给出错误

Solutions Collecting From Web of "com.android.builder.packaging.DuplicateFileException:复制在META-INF / maven / com.fasterxml.jackson.core / jackson-databind / pom.xml中复制的文件"

而不是这个

 packagingOptions { exclude 'META-INF/LICENSE' exclude 'META-INF/NOTICE' } 

尝试这个

  packagingOptions { exclude 'META-INF/DEPENDENCIES.txt' exclude 'META-INF/LICENSE.txt' exclude 'META-INF/NOTICE.txt' exclude 'META-INF/NOTICE' exclude 'META-INF/LICENSE' exclude 'META-INF/DEPENDENCIES' exclude 'META-INF/notice.txt' exclude 'META-INF/license.txt' exclude 'META-INF/dependencies.txt' exclude 'META-INF/LGPL2.1' } 

还有更多的事情

删除这一行

 apply plugin: 'com.google.gms.google-services' 

从底部,并添加到顶部之后,这个apply plugin: 'com.android.application'

 apply plugin: 'com.android.application' apply plugin: 'com.google.gms.google-services' 

更新:

只是删除

 compile fileTree(dir: 'libs', include: '*.jar') 

并应用依赖关系。

在gredle中进行更改,您也必须exclude maven。

 packagingOptions { exclude 'META-INF/LICENSE' exclude 'META-INF/NOTICE' exclude 'META-INF/maven } 

如果你使用的是google-play-service你可以排除像annotation

 dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) testCompile 'junit:junit:4.12' compile ('com.google.android.gms:play-services:8.1.0'){ exclude group: 'com.google.guava' } } 

或者你也可以试试这个

 configurations { all*.exclude group: 'com.android.support', module: 'support-v4' }