错误::在打包APK期间重复文件


144

Android Studio。在应用程序运行期间出现这种错误。

Error:Execution failed for task ':app:packageDebug'. Duplicate files copied in APK META-INF/notice.txt

build.gradle

apply plugin: 'android'

android {
    compileSdkVersion 19
    buildToolsVersion "19.0.1"

    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/ASL2.0'
    }

    defaultConfig {
        minSdkVersion 7
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
}

dependencies {
    compile 'com.android.support:appcompat-v7:19.0.1'
    compile 'com.j256.ormlite:ormlite-android:4.48'
    compile 'org.codehaus.jackson:jackson-core-asl:1.9.13'
    compile 'org.codehaus.jackson:jackson-mapper-asl:1.9.13'
    compile 'com.octo.android.robospice:robospice:1.4.11'
    compile 'com.octo.android.robospice:robospice-spring-android:1.4.11'
}

如何解决此错误?

已编辑

这些排除选项解决了我的问题:

packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/ASL2.0'
    }


2
这不是重复的!其他提问者通过添加排除选项解决了他们的错误。但是正如大家所看到的,我添加了这些选项,但问题并没有消失。
Robertas Setkus 2014年


有没有关于这个问题的任何想法stackoverflow.com/questions/30364950/...
Jithu PS

那解决了我的问题。谢谢
Reshma

Answers:


56

我认为字符串比较区分大小写。尝试exclude 'META-INF/notice.txt'


我的答案是尝试使用notice.txt而不是NOTICE.txt?尽管该错误实际上与发生排除的错误有所不同。你有META-INF/notice.txt文件src/main/resources/吗?
Xavier Ducrohet 2014年

抱歉,泽维尔。那我不明白你的回答。现在我明白你的意思了。我尝试更改为,exclude 'META-INF/notice.txt'但随后控制台提示Duplicate files copied in APK META-INF/NOTICE.txt。奇怪,不是吗?resources下没有目录C:\PathToAndroidStudioProject\src\main
罗伯塔斯·塞库斯

1
如果两者都放 exclude 'META-INF/notice.txt'exclude 'META-INF/NOTICE.TXT',是否有效?
Xavier Ducrohet 2014年

谢谢。有帮助。:)
Robertas Setkus 2014年

1
在“ android”部分的build.gradle文件中,尝试添加: packagingOptions { exclude 'META-INF/ASL2.0' exclude 'META-INF/LICENSE' }
Krystian

22

我认为您只需要在build.gradle中包括这些选项:

packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
    }

1
最终在实现这一目标之后,我解决了该查询。谢谢男人:)
Hardik Joshi 2015年

10

简短答案:

请使用查看详细的gradle输出,gradle assemble并注意重复的文件,并使用以下命令排除它们:

android {
  packagingOptions {
    exclude 'META-INF/notice.txt'
  }
}

长答案:

assemble从命令行运行gradle任务以获取详细输出:

./gradlew assemble || gradle assemble

这会自动显示要排除的内容:

studioWorkspace/CCDroid git:(master)  ± ./gradlew assembleDebug
:app:preBuild
:app:compileDebugNdk UP-TO-DATE
:app:preDebugBuild
:app:checkDebugManifest
:app:preReleaseBuild
:app:prepareComAndroidSupportAppcompatV72200Library UP-TO-DATE
:app:prepareComAndroidSupportSupportV42200Library UP-TO-DATE
:app:prepareDebugDependencies
:app:compileDebugAidl UP-TO-DATE
:app:compileDebugRenderscript UP-TO-DATE
:app:generateDebugBuildConfig UP-TO-DATE
:app:generateDebugAssets UP-TO-DATE
:app:mergeDebugAssets UP-TO-DATE
:app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources UP-TO-DATE
:app:mergeDebugResources UP-TO-DATE
:app:processDebugManifest UP-TO-DATE
:app:processDebugResources UP-TO-DATE
:app:generateDebugSources UP-TO-DATE
:app:compileDebugJava UP-TO-DATE
:app:preDexDebug UP-TO-DATE
:app:dexDebug UP-TO-DATE
:app:processDebugJavaRes UP-TO-DATE
:app:validateDebugSigning
:app:packageDebug
Error: duplicate files during packaging of APK /Users/shubham/code/studioProjects/CCDroid/app/build/outputs/apk/app-debug-unaligned.apk
    Path in archive: LICENSE
    Origin 1: /Users/shubham/.gradle/caches/modules-2/files-2.1/org.projectlombok/lombok/1.14.8/8ac073941721e0b521ec8e8bad088b1e7b8cd332/lombok-1.14.8.jar
    Origin 2: /Users/shubham/.gradle/caches/modules-2/files-2.1/org.mockito/mockito-all/1.8.4/5c97d8b6e715ed941aeb93d6fc401ab3eb18a566/mockito-all-1.8.4.jar
You can ignore those files in your build.gradle:
    android {
      packagingOptions {
        exclude 'LICENSE'
      }
    }
:app:packageDebug FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:packageDebug'.
> Duplicate files copied in APK LICENSE
    File 1: /Users/shubham/.gradle/caches/modules-2/files-2.1/org.projectlombok/lombok/1.14.8/8ac073941721e0b521ec8e8bad088b1e7b8cd332/lombok-1.14.8.jar
    File 2: /Users/shubham/.gradle/caches/modules-2/files-2.1/org.projectlombok/lombok/1.14.8/8ac073941721e0b521ec8e8bad088b1e7b8cd332/lombok-1.14.8.jar


* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 11.863 secs

参见输出部分:

android {
  packagingOptions {
    exclude 'LICENSE'
  }
}

它甚至显示源自重复文件(LICENSE)的依赖项列表。参见输出中带有Origin#的行。


有没有关于这个问题的任何想法stackoverflow.com/questions/30364950/...
Jithu PS

1
尽管这对我来说是正确的,但我几乎忽略了您的回答。我建议将答案放在帖子的顶部:android {packagingOptions {exclude'LICENSE'}},然后是解释和长gradle输出(与答案基本无关)。这部分是您可以忽略那些文件在您的build.gradle中:android {packagingOptions {
exclude'LICENSE

做完了 非常感谢@gorbysbm。
Shubham Chaudhary

6

将此添加到您的build.gradle文件中...

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

像这样...

android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
    applicationId "your package name"
    minSdkVersion 14
    targetSdkVersion 25
    versionCode 30
    versionName "3.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
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'
}
}

3

这不只一个错误,您是对的。

apply plugin: 'android-library'

添加此:: android { packagingOptions { exclude 'META-INF/ASL2.0' exclude 'META-INF/LICENSE' exclude 'META-INF/NOTICE' } }

第一个错误是由文件重复引起的,第二个错误是由许可和通知文件引起的。它会在以后工作

编辑::请参阅此处有关发现问题的帖子:: Android Gradle插件0.7.0:“在打包APK期间重复文件”


有没有关于这个问题的任何想法stackoverflow.com/questions/30364950/...
Jithu PS

1

这对我有用

android {
...

    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/ASL2.0'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/license.txt'
    }
}

1

有趣的是,当我从gradle中删除此行时,它起作用了:

compile 'org.apache.commons:commons-lang3:3.3.1'

0

我必须花点时间才能找到PackagingOptions的正确位置。解决重复文件问题,以解决jackson-core:2.2.2jackson-databind:2.2.2之间的冲突 。DSL似乎最近也发生了变化,因此在具有buildTools 23的最新Android Studio 1.4.1中,您必须放置android。包装选项与compileOptions处于同一级别,并且不在任何模型{android {大括号内!

model { 
   android {
        compileSdkVersion = 21
        buildToolsVersion = "23.0.1"

        defaultConfig.with {
              applicationId = "com.android.sensorgraph"
              minSdkVersion.apiLevel = 21
              targetSdkVersion.apiLevel = 22
        }
   }

   android.packagingOptions {
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/NOTICE'
   }
   compileOptions.with {
        sourceCompatibility = JavaVersion.VERSION_1_7
        targetCompatibility = JavaVersion.VERSION_1_7
   }
} 
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.