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


我正在创建一个使用RestAPI来获取数据的应用程序,对于该操作,我使用改造2,okhttp3和jackson将json解析为对象,我的应用程序也使用Firebase云消息传递

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

错误:任务':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.core/jackson-databind/2.2.2/3c8f6018eaa72d43b261181e801e6f8676c16ef6/jackson-databind-2.2.2.jar

我在用 Android Studio 2.1.1 和 OS X EI Capitan 10.11.2

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

转换器 - 杰克逊-2.0.2.jar

杰克逊的注解 - 2.7.0.jar

杰克逊核心2.7.2.jar

杰克逊 - 数据绑定 - 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'
    
    
}

还尝试了无效的缓存和重启,还重建,清理,甚至我尝试手动删除缓存但仍然给我错误

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


12555
2018-05-25 05:40


起源



答案:


而不是这个

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'

从Bottom开始,在此之后添加到Top apply plugin: 'com.android.application'

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

更新:

只是删除

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

并应用依赖项。


13
2018-05-25 05:44



错误更改为错误:任务':app:transformClassesWithJarMergingForDebug'的执行失败。 > com.android.build.api.transform.TransformException:java.util.zip.ZipException:重复条目:com / fasterxml / jackson / databind / AbstractTypeResolver.class - Indrajit Sinh Rayjada
@IndrajitSinhRayjada看到我更新的答案。 - Ironman
你建议我删除它,但我需要所有这些库,我在我的应用程序上使用它 - Indrajit Sinh Rayjada
@IndrajitSinhRayjada删除这一行并添加依赖关系抱歉我写的东西很短。 - Ironman
你的工作就像魅力一样,谢谢@ironman你疯了我的一天:),我接受了 - Indrajit Sinh Rayjada


答案:


而不是这个

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'

从Bottom开始,在此之后添加到Top apply plugin: 'com.android.application'

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

更新:

只是删除

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

并应用依赖项。


13
2018-05-25 05:44



错误更改为错误:任务':app:transformClassesWithJarMergingForDebug'的执行失败。 > com.android.build.api.transform.TransformException:java.util.zip.ZipException:重复条目:com / fasterxml / jackson / databind / AbstractTypeResolver.class - Indrajit Sinh Rayjada
@IndrajitSinhRayjada看到我更新的答案。 - Ironman
你建议我删除它,但我需要所有这些库,我在我的应用程序上使用它 - Indrajit Sinh Rayjada
@IndrajitSinhRayjada删除这一行并添加依赖关系抱歉我写的东西很短。 - Ironman
你的工作就像魅力一样,谢谢@ironman你疯了我的一天:),我接受了 - Indrajit Sinh Rayjada


你需要改变gredle exclude 对梅文来说也是如此。

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

2
2018-05-25 05:46



错误更改为错误:任务':app:transformClassesWithJarMergingForDebug'的执行失败。 > com.android.build.api.transform.TransformException:java.util.zip.ZipException:重复条目:com / fasterxml / jackson / annotation / JacksonAnnotation.class - Indrajit Sinh Rayjada
我更新了答案 - Devendra Singh
感谢您的帮助,接受并且。工作就像魅力:) - Indrajit Sinh Rayjada