【问题标题】:com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META-INF/INDEX.LIST [duplicate]com.android.builder.packaging.DuplicateFileException:在 APK META-INF/INDEX.LIST 中复制的重复文件 [重复]
【发布时间】:2017-10-02 06:43:46
【问题描述】:

之后我添加了两个 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 中复制的文件重复 文件 1:C:\AndroidStudioProjects\test\app\libs\jackson.jar 文件 2: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')
}

我在google上搜索,找到了一些解决方案,例如:

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

但它们不起作用。

我该如何解决这个问题?

谢谢,

塔尔

【问题讨论】:

    标签: java android gradle


    【解决方案1】:

    在build.gradle的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'
    }
    

    【讨论】:

    • 我添加并重建项目,但是当我运行项目时异常返回
    猜你喜欢
    • 1970-01-01
    • 2016-09-22
    • 2016-08-10
    • 1970-01-01
    • 2014-07-06
    • 2016-12-27
    • 2017-11-14
    • 2017-12-08
    相关资源
    最近更新 更多