com.android.builder.packaging.DuplicateFileException:在APK META-INF / INDEX.LIST中复制的重复文件

时间:2017-10-02 06:43:46

标签: java android gradle

之后我添加了两个jar文件:     编译文件(' libs / json-simple.jar')     编译文件(' libs / core-renderer-minimal.jar') 我收到此错误消息: 错误:任务执行失败':app:transformResourcesWithMergeJavaResForDebug'。

  

com.android.build.api.transform.TransformException:com.android.builder.packaging.DuplicateFileException:在APK META-INF / INDEX.LIST中复制的重复文件       File1:C:\ AndroidStudioProjects \ test \ app \ libs \ jackson.jar       File2:C:\ AndroidStudioProjects \ test \ app \ libs \ core-renderer-minimal.jar   我没有找到这个例外的解决方案。

我的build.gradle:

    apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "26.0.1"
    defaultConfig {
        applicationId "adms.test"
        minSdkVersion 21
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    dexOptions {
        javaMaxHeapSize "4g"
    }

    packagingOptions {
        exclude 'META-INF/license.txt'
    }
}

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 files('libs/aspose-pdf-17.7-android-via-java.jar')
    compile files('libs/jackson.jar')
    compile files('libs/json-simple.jar')
    compile files('libs/org.apache.commons.io.jar')
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    testCompile 'junit:junit:4.12'
    compile files('libs/acrobat-1.1.jar')
    compile files('libs/xml-apis-xerces-2.9.1.jar')
    compile files('libs/com.lowagie.text-2.1.7.jar')
    compile files('libs/core-renderer-minimal.jar')
}

我在谷歌搜索并找到了一些解决方案,例如:

    packagingOptions {
        pickFirst 'META-INF/INDEX.LIST'
        pickFirst 'META-INF/LICENSE'
        pickFirst 'META-INF/io.netty.versions.properties'
    }

packagingOptions {
   pickFirst  'META-INF/license.txt'
}

packagingOptions {
  exclude 'META-INF/maven/com.squareup.okhttp3/okhttp/pom.properties'
  exclude 'META-INF/maven/com.squareup.okio/okio/pom.xml'
  exclude 'META-INF/maven/com.squareup.okhttp3/okhttp/pom.xml'
  exclude 'META-INF/maven/com.squareup.okio/okio/pom.properties'
}

但他们没有工作。

我该如何解决这个问题?

谢谢,

塔尔

1 个答案:

答案 0 :(得分:0)

在build.gradle和rebuild项目中的android标记中添加以下代码;

  packagingOptions {
    exclude 'META-INF/NOTICE' // will not include NOTICE file
    exclude 'META-INF/LICENSE' // will not include LICENSE file
    exclude 'META-INF/DEPENDENCIES' // will not include LICENSE file
    exclude 'META-INF/LICENSE.txt'
    exclude 'META-INF/NOTICE.txt'
}