android - com.android.builder.packaging.DuplicateFileException : Duplicate files copied in APK META-INF/maven/com. fasterxml.jackson.core/jackson-databind/pom.xml

标签 android gradle jackson android-gradle-plugin android-studio-2.1

我正在创建一个使用 RestAPI 来获取数据的应用程序,对于该操作,我正在使用 retrofit 2、okhttp3 和 jackson 将 json 解析为对象,我的应用程序还使用 Firebase Cloud Messaging

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

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

com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in 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.1OS X El Capitan 10.11.2

项目库文件夹中添加了一些库

converter-jackson-2.0.2.jar

jackson-annotations-2.7.0.jar

jackson-core-2.7.2.jar

jackson-databind-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 依赖项时它总是出错。

最佳答案

而不是这个

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

并应用依赖项。

关于android - com.android.builder.packaging.DuplicateFileException : Duplicate files copied in APK META-INF/maven/com. fasterxml.jackson.core/jackson-databind/pom.xml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37428636/

相关文章:

android - 自动关闭警报对话框

android - 我们需要在 Android 中替换 strings.xml 文件中的逗号吗?

android - 无法编译 'com.firebaseui:firebase-ui-database:2.1.1'

Android 测试 BuildConfig 字段

android - TransformException : java. util.zip.ZipException : duplicate entry: android/support/annotation/StyleRes. 类

android - 全屏呈现 Intent

android - list 合并失败 : uses-sdk:minSdkVersion 1 cannot be smaller than version 14 declared in library

java - Jackson 将子 JSON 反序列化为父属性

java - jackson 无法将 json 转换为 map 列表

java - 当它是一个整数时,没有字符串参数构造函数/工厂方法从字符串值反序列化