错误: : APK 打包过程中重复的文件

Android Studio 在应用程序运行过程中出现了这种错误。

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

建造,分级

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'
}
69476 次浏览

我认为字符串比较是区分大小写的

简短的回答:

查看使用 gradle assemble和 注意重复的文件,并使用以下方法排除它们:

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

答案很长:

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

./gradlew 装配 | | gradle 装配

这会自动显示排除哪些内容:

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)。

不止一个错误,你是对的。

apply plugin: 'android-library'下面

补充一点: 机器人{ 包装选项{ 排除“ META-INF/ASL2.0” 排除“ META-INF/LICENSE” 排除“ META-INF/NOTICE” } }

第一个错误是由文件重复,第二个错误是由许可证和通知文件。 之后会有用的

编辑: 点击这里查看我关于识别问题的文章: Android Gradle plugin 0.7.0: “ APK 打包过程中的重复文件”

我认为你需要在 建造,分级中只包括这些选项:

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

将这个添加到 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'
}
}

这对我有用

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

有趣的是,当我用 删除表示这句话的时候,它起作用了:

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

我不得不玩了一点,以找到正确的位置打包选项。解决 Jackson-core: 2.2.2和 < strong > jackson-database: 2.2.2之间冲突的重复文件问题 此外,DSL 最近似乎也发生了变化 因此,在最近的 Android Studio 1.4.1和 buildTools 23中,你必须把 Android.package 选项放在相同的级别上,而不是放在任何 型号{机器人{括号中!

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