Android gradle 构建给出了 DuplicateFileException

标签 android android-studio android-gradle-plugin build.gradle

您好,在添加 apache poi gradle build 之后,我得到了这个期望。能否请您解释一下如何解决它。

我试过用很多方法排除包选项,都没有用

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.1.0'
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:design:25.1.0'
    compile 'com.android.support:cardview-v7:25.1.0'
    compile 'org.greenrobot:greendao:3.2.0'
    compile group: 'org.apache.poi', name: 'poi-ooxml', version: '3.9'

}

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

com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META-INF/LICENSE File1: /home/surendra/.gradle/caches/modules-2/files-2.1/org.apache.poi/poi-ooxml-schemas/3.9/4c514498f0e82cccfdd3208b9caff2f45158db4a/poi-ooxml-schemas-3.9.jar File2: /home/surendra/.gradle/caches/modules-2/files-2.1/org.apache.poi/poi-ooxml/3.9/bbe83c739d22eecfacd06d7e0b99ba13277040ed/poi-ooxml-3.9.jar File3: /home/surendra/.gradle/caches/modules-2/files-2.1/org.apache.poi/poi/3.9/5d5e41354e88322e4bc590b31f3d2d1d52b3e6ac/poi-3.9.jar

最佳答案

尝试使用以下代码排除重复的文件

packagingOptions {
    exclude 'META-INF/DEPENDENCIES'
    exclude 'META-INF/NOTICE'
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/LICENSE.txt'
    exclude 'META-INF/NOTICE.txt'
    pickFirst  'META-INF/license.txt'
        }

关于Android gradle 构建给出了 DuplicateFileException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45143336/

相关文章:

android - 如何在不使用谷歌地图方向 api 的情况下查找 Android 应用程序中 2 个地理点之间的距离(通过公路)?

android-studio - 编译错误: "-Xcoroutines has no effect: coroutines are enabled anyway in 1.3 and beyond"

以 Android 库项目作为外部模块的 Android 应用程序

java - Android 在加载 URL 时显示进度对话框

android - RecyclerView 适配器中的导航组件

java - 如何将多种类型的用户重定向到各自的 Activity?

android - 在 Android Studio 的 AAR 中包含两个模块

android-studio - Android 构建错误 DexIndexOverflowException

android - 设置 Gradle 以在 Android Studio 中运行 Java 可执行文件

android - 是什么导致 Android 设备华硕 Zenfone 2 警报管理器无法正常工作?