在Android Studio中使用Gradle添加编译时重复文件

Sav*_*der 6 android gradle android-studio build.gradle android-gradle-plugin

我正在尝试将Jackson添加到我的Android Studio项目中,我将其添加到gradle中的依赖项:

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:19.+'
    compile 'com.android.support:support-v4:19.+'
    compile files('libs/universal-image-loader-1.9.2.jar')
    compile 'com.google.android.gms:play-services:+'
    compile 'com.fasterxml.jackson.core:jackson-databind:2.4.3'
}
Run Code Online (Sandbox Code Playgroud)

Gradle构建运行正常,但是当我想在Android Studio中运行测试时,它会给我以下错误:

Error:Gradle: duplicate files during packaging of APK .../app/build/outputs/apk/app-debug-unaligned.apk

Error:Gradle: Execution failed for task ':app:packageDebug'.
Run Code Online (Sandbox Code Playgroud)

在APK META-INF/LICENSE文件1中复制的重复文件:... /.gradle/caches/modules-2/files-2.1/com.fasterxml.jackson.core/jackson-annotations/2.4.3/a30ec6f59b6d31b2df06fa73925fda2fc7e84486/jackson- annotations-2.4.3.jar文件2:... /.gradle/caches/modules-2/files-2.1/com.fasterxml.jackson.core/jackson-annotations/2.4.3/a30ec6f59b6d31b2df06fa73925fda2fc7e84486/jackson-annotations-2.4 .3.jar

我尝试在Android Studio中使缓存失效,但它不起作用.请问有人可以帮助我吗?

Gab*_*tti 13

您可以排除将此块添加到您的build.gradle:

android {
    packagingOptions {
        exclude 'META-INF/LICENSE.txt'
    }
}
Run Code Online (Sandbox Code Playgroud)

  • 添加排除'META-INF/LICENSE'后排除'META-INF/NOTICE' (4认同)
  • 你能解释一下为什么会这样吗? (2认同)