【问题标题】:Android app not building: Duplicate files copied in APK META-INF/INDEX.LISTAndroid 应用程序未构建:在 APK META-INF/INDEX.LIST 中复制的重复文件
【发布时间】:2016-03-30 03:23:46
【问题描述】:

我在尝试运行 Android 应用时遇到以下错误。

Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'.
> com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META-INF/INDEX.LIST
    File1: /Users/Antrromet/.gradle/caches/modules-2/files-2.1/org.apache.xmlbeans/xmlbeans/2.6.0/29e80d2dd51f9dcdef8f9ffaee0d4dc1c9bbfc87/xmlbeans-2.6.0.jar
    File2: /Users/Antrromet/.gradle/caches/modules-2/files-2.1/edu.ucar/cdm/4.5.5/af1748a3d024069cb7fd3fc2591efe806c914589/cdm-4.5.5.jar
    File3: /Users/Antrromet/.gradle/caches/modules-2/files-2.1/edu.ucar/httpservices/4.5.5/ee5f217be599e5e03f7f0e55e03f9e721a154f62/httpservices-4.5.5.jar
    File4: /Users/Antrromet/.gradle/caches/modules-2/files-2.1/edu.ucar/netcdf4/4.5.5/675d63ecc857c50dd50858011b670160aa30b62/netcdf4-4.5.5.jar
    File5: /Users/Antrromet/.gradle/caches/modules-2/files-2.1/edu.ucar/grib/4.5.5/cfe552910e9a8d57ce71134796abb281a74ead16/grib-4.5.5.jar
    File6: /Users/Antrromet/.gradle/caches/modules-2/files-2.1/edu.ucar/udunits/4.5.5/d8c8d65ade13666eedcf764889c69321c247f153/udunits-4.5.5.jar

我知道herehere 有类似的问题,我从他们两个那里得到了提示。这就是我的 gradle 文件的样子。

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "com.antrromet.androidtikaparser"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'

        exclude 'META-INF/maven/edu.ucar/udunits/pom.xml'
        exclude 'META-INF/maven/edu.ucar/udunits/pom.properties'

        exclude 'META-INF/maven/edu.ucar/netcdf4/pom.xml'
        exclude 'META-INF/maven/edu.ucar/netcdf4/pom.properties'

        exclude 'META-INF/maven/edu.ucar/cdm/pom.xml'
        exclude 'META-INF/maven/edu.ucar/cdm/pom.properties'

        exclude 'META-INF/maven/edu.ucar/grib/pom.xml'
        exclude 'META-INF/maven/edu.ucar/grib/pom.properties'

        exclude 'META-INF/maven/org.apache.xmlbeans/xmlbeans/pom.xml'
        exclude 'META-INF/maven/org.apache.xmlbeans/xmlbeans/pom.properties'

        exclude 'META-INF/maven/edu.ucar/httpservices/pom.xml'
        exclude 'META-INF/maven/edu.ucar/httpservices/pom.properties'
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.2.1'
    compile('org.apache.tika:tika-parsers:1.12') {
        exclude group: 'commons-logging', module: 'commons-logging'
        exclude group: 'org.json', module: 'json'
        exclude group: 'org.apache.httpcomponents', module: 'httpclient'
    }
}

关于如何解决这个问题的任何建议?提前致谢!

编辑 1

当我添加exclude 'META-INF/INDEX.LIST'时,错误变为如下,

Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'.
> com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META-INF/services/org.apache.sis.storage.DataStoreProvider
    File1: /Users/Antrromet/.gradle/caches/modules-2/files-2.1/org.apache.sis.storage/sis-storage/0.5/29d1ea6422b68fbfe1f1702f122019ae376ee2c8/sis-storage-0.5.jar
    File2: /Users/Antrromet/.gradle/caches/modules-2/files-2.1/org.apache.sis.storage/sis-netcdf/0.5/2b416e4506caebe7df6dd21b878dae888e0eea39/sis-netcdf-0.5.jar

然后如果你添加以下内容,

exclude 'META-INF/maven/org.apache.sis.storage/sis-netcdf/pom.xml'
exclude 'META-INF/maven/org.apache.sis.storage/sis-netcdf/pom.properties'

exclude 'META-INF/maven/org.apache.sis.storage/sis-storage/pom.xml'
exclude 'META-INF/maven/org.apache.sis.storage/sis-storage/pom.properties'

它与上面的错误完全相同。它不会改变。

【问题讨论】:

  • 你试过排除META-INF/INDEX.LIST吗?
  • @cricket_007 我已经尝试过了。检查我编辑的问题。
  • 所有这些错误都是来自 Tika 吗?
  • @cricket_007 是的,这是我尝试使用的唯一库。我猜是,Tika 内部正在使用这些罐子,因此存在冲突。但我确信在打包 apk 时必须有办法在 Android 中阻止这种情况。
  • Tika Android 的第一个结果给了我这个stackoverflow.com/questions/8135775/…

标签: android android-studio gradle android-gradle-plugin


【解决方案1】:

您需要添加以下排除:

exclude 'META-INF/services/org.apache.sis.storage.DataStoreProvider'

【讨论】:

  • 这确实解决了我的特定问题,但是在我这样做之后,我不得不排除其他一些事情,而且它一直在继续!我现在刚刚离开,将在更好的时间详细检查。附言对于如此延迟的回复,我深表歉意。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-04-21
  • 2016-12-13
  • 1970-01-01
  • 2016-08-10
  • 2016-10-01
  • 2017-10-07
  • 2016-12-27
相关资源
最近更新 更多