Android 错误 :: 打包 APK 期间出现重复文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22467127/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Error :: duplicate files during packaging of APK
提问by Robertas Setkus
Android Studio. I'm getting this kind of error during application run.
安卓工作室。我在应用程序运行期间遇到这种错误。
Error:Execution failed for task ':app:packageDebug'. Duplicate files copied in APK META-INF/notice.txt
Error:Execution failed for task ':app:packageDebug'. Duplicate files copied in APK META-INF/notice.txt
build.gradle
构建.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.Hymanson:Hymanson-core-asl:1.9.13'
compile 'org.codehaus.Hymanson:Hymanson-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'
}
How can I fix this error?
我该如何解决这个错误?
EDITED
已编辑
These exclude options solved my problem:
这些排除选项解决了我的问题:
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'
}
采纳答案by Xavier Ducrohet
I think the string comparison is case sensitive. try with exclude 'META-INF/notice.txt'
我认为字符串比较区分大小写。尝试exclude 'META-INF/notice.txt'
回答by Gent Berani
I think you need to include only these options in build.gradle:
我认为您只需要在build.gradle 中包含这些选项:
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
}
回答by Shubham Chaudhary
Short Answer:
简答:
See the detailed gradle output using gradle assemble
and
note the files that are duplicate and exclude them using:
使用查看详细的 gradle 输出gradle assemble
并注意重复的文件并使用以下方法排除它们:
android {
packagingOptions {
exclude 'META-INF/notice.txt'
}
}
Long Answer:
长答案:
Run the assemble
gradle task from command line for detailed output:
assemble
从命令行运行gradle 任务以获取详细输出:
./gradlew assemble || gradle assemble
./gradlew assemble || gradle assemble
This automatically shows what to exclude:
这会自动显示要排除的内容:
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
See this part in output:
在输出中看到这部分:
android {
packagingOptions {
exclude 'LICENSE'
}
}
It even shows the list of dependencies which originated duplicate files (LICENSE). See the lines with Origin #in the output.
它甚至显示了源自重复文件(许可证)的依赖项列表。查看输出中带有Origin #的行。
回答by vrbsm
Add this in your build.gradle file ...
将此添加到您的 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'
}
like this...
像这样...
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'
}
}
回答by Pian0_M4n
It's more than one error, you are right.
错误不止一个,你是对的。
Under apply plugin: 'android-library'
在下面 apply plugin: 'android-library'
add this ::
android {
packagingOptions {
exclude 'META-INF/ASL2.0'
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
}
}
添加这个::
android {
packagingOptions {
exclude 'META-INF/ASL2.0'
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
}
}
1st error is by file duplicates, 2nd is by LICENSE and NOTICE files. It will work after
第一个错误是文件重复,第二个错误是许可证和通知文件。它会在之后工作
EDIT:: See my post here about identifying the problems:: Android Gradle plugin 0.7.0: "duplicate files during packaging of APK"
编辑:: 在这里查看我关于识别问题的帖子:: Android Gradle 插件 0.7.0:“在打包 APK 期间出现重复文件”
回答by Joolah
this works for me
这对我有用
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'
}
}
回答by Lazy
Interestingly, when I deletedthis line from gradle, it worked:
有趣的是,当我从 gradle 中删除这一行时,它起作用了:
compile 'org.apache.commons:commons-lang3:3.3.1'
回答by U.V.
I had to play around a bit to find the right location for the packagingOptions. Solving the duplicate file problem for a conflict between Hymanson-core:2.2.2and Hymanson-databind:2.2.2Also the DSL seems to have changed recently So in the recent Android Studio 1.4.1 with buildTools 23 you have to put android.packaging options on the same level as compileOptions AND NOT inside any model { android {braces !
我不得不四处寻找一下包装选项的正确位置。解决Hymanson-core:2.2.2和Hymanson-databind:2.2.2之间冲突的重复文件问题 DSL 最近似乎也发生了变化 所以在最近的 Android Studio 1.4.1 和 buildTools 23 中,您必须将 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
}
}