Android Gradle 插件 0.7.0:“APK 打包过程中出现重复文件”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20673625/
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
Android Gradle plugin 0.7.0: "duplicate files during packaging of APK"
提问by David Lawson
Using Android Gradle plugin 0.7.0 with the following build.gradle
:
使用 Android Gradle 插件 0.7.0 与以下内容build.gradle
:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.0'
}
}
apply plugin: 'android'
repositories {
maven { url "https://android-rome-feed-reader.googlecode.com/svn/maven2/releases" }
maven { url "http://dl.bintray.com/populov/maven" }
mavenCentral()
}
android {
compileSdkVersion 19
buildToolsVersion '18.1.1'
defaultConfig {
minSdkVersion 9
targetSdkVersion 19
}
buildTypes {
release {
runProguard true
proguardFile getDefaultProguardFile('proguard-android-optimize.txt')
}
}
productFlavors {
defaultFlavor {
proguardFile 'proguard-rules.txt'
}
}
sourceSets {
instrumentTest.setRoot('src/instrumentTest')
}
}
configurations {
apt
}
ext.androidAnnotationsVersion = '2.7.1';
dependencies {
compile 'com.android.support:support-v4:18.0.0'
compile 'com.viewpagerindicator:library:2.4.1@aar'
compile 'com.google.code.android-rome-feed-reader:android-rome-feed-reader:1.0.0-r2'
compile 'org.jdom:jdom:1.1.1-android-fork'
apt "com.googlecode.androidannotations:androidannotations:${androidAnnotationsVersion}"
compile "com.googlecode.androidannotations:androidannotations-api:${androidAnnotationsVersion}"
compile 'com.google.code.gson:gson:2.2.4'
compile 'com.j256.ormlite:ormlite-android:4.47'
compile 'com.j256.ormlite:ormlite-core:4.47'
compile 'org.springframework.android:spring-android-core:1.0.1.RELEASE'
compile 'org.springframework.android:spring-android-rest-template:1.0.1.RELEASE'
compile 'com.prolificinteractive:actionbarsherlock:4.3.1@aar'
compile 'com.google.code.geocoder-java:geocoder-java:0.15'
compile files('libs/CWAC-Pager.jar')
}
android.applicationVariants.all { variant ->
aptOutput = file("${project.buildDir}/source/apt_generated/${variant.dirName}")
println "****************************"
println "variant: ${variant.name}"
println "manifest: ${variant.processResources.manifestFile}"
println "aptOutput: ${aptOutput}"
println "****************************"
variant.javaCompile.doFirst {
println "*** compile doFirst ${variant.name}"
aptOutput.mkdirs()
variant.javaCompile.options.compilerArgs += [
'-processorpath', configurations.apt.getAsPath(),
'-AandroidManifestFile=' + variant.processResources.manifestFile,
'-s', aptOutput
]
}
}
gives the error Duplicate files copied in APK META-INF/LICENSE.txt
:
给出错误Duplicate files copied in APK META-INF/LICENSE.txt
:
WARNING: Dependency commons-logging:commons-logging:1.0.4 is ignored for defaultFlavorDebug as it may be conflicting with the internal version provided by Android.
In case of problem, please repackage it with jarjar to change the class packages
WARNING: Dependency commons-logging:commons-logging:1.0.4 is ignored for defaultFlavorRelease as it may be conflicting with the internal version provided by Android.
In case of problem, please repackage it with jarjar to change the class packages
Creating properties on demand (a.k.a. dynamic properties) has been deprecated and is scheduled to be removed in Gradle 2.0. Please read http://gradle.org/docs/current/dsl/org.gradle.api.plugins.ExtraPropertiesExtension.html for information on the replacement for dynamic properties.
Deprecated dynamic property: "aptOutput" on "com.android.build.gradle.internal.api.ApplicationVariantImpl_Decorated@5705013c", value: "/Users/david/Developer...".
****************************
variant: defaultFlavorDebug
manifest: /Users/david/Developer/.../build/manifests/defaultFlavor/debug/AndroidManifest.xml
aptOutput: /Users/david/Developer/.../build/source/apt_generated/defaultFlavor/debug
****************************
Deprecated dynamic property "aptOutput" created in multiple locations.
****************************
variant: defaultFlavorRelease
manifest: /Users/david/Developer/.../build/manifests/defaultFlavor/release/AndroidManifest.xml
aptOutput: /Users/david/Developer/.../build/source/apt_generated/defaultFlavor/release
****************************
:TravelGuard:compileDefaultFlavorDebugNdk UP-TO-DATE
:TravelGuard:preBuild UP-TO-DATE
:TravelGuard:preDefaultFlavorDebugBuild UP-TO-DATE
:TravelGuard:preDefaultFlavorReleaseBuild UP-TO-DATE
:TravelGuard:prepareComProlificinteractiveActionbarsherlock431Library UP-TO-DATE
:TravelGuard:prepareComViewpagerindicatorLibrary241Library UP-TO-DATE
:TravelGuard:prepareDefaultFlavorDebugDependencies
:TravelGuard:compileDefaultFlavorDebugAidl UP-TO-DATE
:TravelGuard:compileDefaultFlavorDebugRenderscript UP-TO-DATE
:TravelGuard:generateDefaultFlavorDebugBuildConfig UP-TO-DATE
:TravelGuard:mergeDefaultFlavorDebugAssets UP-TO-DATE
:TravelGuard:mergeDefaultFlavorDebugResources UP-TO-DATE
:TravelGuard:processDefaultFlavorDebugManifest UP-TO-DATE
:TravelGuard:processDefaultFlavorDebugResources UP-TO-DATE
:TravelGuard:generateDefaultFlavorDebugSources UP-TO-DATE
:TravelGuard:compileDefaultFlavorDebugJava
*** compile doFirst defaultFlavorDebug
/Users/david/Developer/.../src/main/java/com/travelguard/service/TravelGuardService.java:53: cannot find symbol
symbol : class TravelGuardPrefs_
location: class com.travelguard.service.TravelGuardService
TravelGuardPrefs_ travelGuardPrefs;
^
/Users/david/Developer/.../src/main/java/com/travelguard/ui/CategoriesActivity.java:14: cannot find symbol
symbol : class AssistanceFragment_
location: package com.travelguard.ui.fragments
import com.travelguard.ui.fragments.AssistanceFragment_;
^
/Users/david/Developer/.../src/main/java/com/travelguard/ui/CategoriesActivity.java:16: cannot find symbol
symbol : class CategoryFragment_
location: package com.travelguard.ui.fragments
import com.travelguard.ui.fragments.CategoryFragment_;
^
/Users/david/Developer/.../src/main/java/com/travelguard/ui/CategoriesActivity.java:17: cannot find symbol
symbol : class ContactFragment_
location: package com.travelguard.ui.fragments
import com.travelguard.ui.fragments.ContactFragment_;
^
/Users/david/Developer/.../src/main/java/com/travelguard/ui/CountriesActivity.java:25: cannot find symbol
symbol : class TravelGuardPrefs_
location: package com.travelguard.service
import com.travelguard.service.TravelGuardPrefs_;
^
/Users/david/Developer/.../src/main/java/com/travelguard/ui/CountriesActivity.java:44: cannot find symbol
symbol : class TravelGuardPrefs_
location: class com.travelguard.ui.CountriesActivity
TravelGuardPrefs_ travelGuardPrefs;
^
/Users/david/Developer/.../src/main/java/com/travelguard/ui/InstructionsActivity.java:18: cannot find symbol
symbol : class AssistanceFragment_
location: package com.travelguard.ui.fragments
import com.travelguard.ui.fragments.AssistanceFragment_;
^
/Users/david/Developer/.../src/main/java/com/travelguard/ui/InstructionsActivity.java:19: cannot find symbol
symbol : class ContactFragment_
location: package com.travelguard.ui.fragments
import com.travelguard.ui.fragments.ContactFragment_;
^
/Users/david/Developer/.../src/main/java/com/travelguard/ui/InstructionsActivity.java:21: cannot find symbol
symbol : class InstructionsFragment_
location: package com.travelguard.ui.fragments
import com.travelguard.ui.fragments.InstructionsFragment_;
^
/Users/david/Developer/.../src/main/java/com/travelguard/ui/MainActivity.java:36: cannot find symbol
symbol : class TravelGuardPrefs_
location: package com.travelguard.service
import com.travelguard.service.TravelGuardPrefs_;
^
/Users/david/Developer/.../src/main/java/com/travelguard/ui/MainActivity.java:40: cannot find symbol
symbol : class AssistanceFragment_
location: package com.travelguard.ui.fragments
import com.travelguard.ui.fragments.AssistanceFragment_;
^
/Users/david/Developer/.../src/main/java/com/travelguard/ui/MainActivity.java:41: cannot find symbol
symbol : class ContactFragment_
location: package com.travelguard.ui.fragments
import com.travelguard.ui.fragments.ContactFragment_;
^
/Users/david/Developer/.../src/main/java/com/travelguard/ui/MainActivity.java:55: cannot find symbol
symbol : class TravelGuardPrefs_
location: class com.travelguard.ui.MainActivity
TravelGuardPrefs_ travelGuardPrefs;
^
/Users/david/Developer/.../src/main/java/com/travelguard/ui/TermsActivity.java:17: cannot find symbol
symbol : class TravelGuardPrefs_
location: package com.travelguard.service
import com.travelguard.service.TravelGuardPrefs_;
^
/Users/david/Developer/.../src/main/java/com/travelguard/ui/TermsActivity.java:23: cannot find symbol
symbol : class TravelGuardPrefs_
location: class com.travelguard.ui.TermsActivity
TravelGuardPrefs_ travelGuardPrefs;
^
Note: Starting AndroidAnnotations annotation processing
Note: AndroidManifest.xml file found: /Users/david/Developer/.../build/manifests/defaultFlavor/debug/AndroidManifest.xml
Note: Number of files generated by AndroidAnnotations: 22
Note: Generating source file: com.travelguard.service.SmartTravellerService_
Note: Generating source file: com.travelguard.service.SmartTravellerWebservice_
Note: Generating source file: com.travelguard.service.TravelGuardPrefs_
Note: Generating source file: com.travelguard.service.TravelGuardService_
Note: Generating source file: com.travelguard.service.TravelGuardWebservice_
Note: Generating source file: com.travelguard.ui.AdviceActivity_
Note: Generating source file: com.travelguard.ui.CategoriesActivity_
Note: Generating source file: com.travelguard.ui.ContactDetailActivity_
Note: Generating source file: com.travelguard.ui.ContactListActivity_
Note: Generating source file: com.travelguard.ui.ContactTravelGuardActivity_
Note: Generating source file: com.travelguard.ui.CountriesActivity_
Note: Generating source file: com.travelguard.ui.InformationActivity_
Note: Generating source file: com.travelguard.ui.InstructionsActivity_
Note: Generating source file: com.travelguard.ui.MainActivity_
Note: Generating source file: com.travelguard.ui.TermsActivity_
Note: Generating source file: com.travelguard.ui.TravelGuardActivity_
Note: Generating source file: com.travelguard.ui.fragments.AdviceDetailFragment_
Note: Generating source file: com.travelguard.ui.fragments.AdviceFragment_
Note: Generating source file: com.travelguard.ui.fragments.AssistanceFragment_
Note: Generating source file: com.travelguard.ui.fragments.CategoryFragment_
Note: Generating source file: com.travelguard.ui.fragments.ContactFragment_
Note: Generating source file: com.travelguard.ui.fragments.InstructionsFragment_
Note: Time measurements: [Whole Processing = 913 ms], [Generate Sources = 358 ms], [Extract Manifest = 163 ms], [Process Annotations = 158 ms], [Extract Annotations = 120 ms], [Validate Annotations = 82 ms], [Find R Classes = 28 ms],
Note: Time measurements: [Whole Processing = 0 ms],
Note: Time measurements: [Whole Processing = 0 ms],
warning: The following options were not recognized by any processor: '[androidManifestFile]'
Note: /Users/david/Developer/.../src/main/java/com/travelguard/ui/ContactDetailActivity.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: /Users/david/Developer/.../src/main/java/com/travelguard/service/SmartTravellerService.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
:TravelGuard:preDexDefaultFlavorDebug UP-TO-DATE
:TravelGuard:dexDefaultFlavorDebug
:TravelGuard:processDefaultFlavorDebugJavaRes UP-TO-DATE
:TravelGuard:validateDebugSigning
:TravelGuard:packageDefaultFlavorDebug
Error: duplicate files during packaging of APK /Users/david/Developer/.../build/apk/TravelGuard-defaultFlavor-debug-unaligned.apk
Path in archive: META-INF/LICENSE.txt
Origin 1: /Users/david/.gradle/caches/modules-2/files-2.1/commons-httpclient/commons-httpclient/3.1/964cd74171f427720480efdec40a7c7f6e58426a/commons-httpclient-3.1.jar
Origin 2: /Users/david/.gradle/caches/modules-2/files-2.1/commons-codec/commons-codec/1.2/397f4731a9f9b6eb1907e224911c77ea3aa27a8b/commons-codec-1.2.jar
:TravelGuard:packageDefaultFlavorDebug FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':TravelGuard:packageDefaultFlavorDebug'.
> Duplicate files copied in APK META-INF/LICENSE.txt
File 1: /Users/david/.gradle/caches/modules-2/files-2.1/commons-httpclient/commons-httpclient/3.1/964cd74171f427720480efdec40a7c7f6e58426a/commons-httpclient-3.1.jar
File 2: /Users/david/.gradle/caches/modules-2/files-2.1/commons-httpclient/commons-httpclient/3.1/964cd74171f427720480efdec40a7c7f6e58426a/commons-httpclient-3.1.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: 21.957 secs
Things were working fine this morning before I updated Android Studio. Any ideas?
在我更新 Android Studio 之前,今天早上一切正常。有任何想法吗?
EDIT: I was able to temporarily fix it by running commands like
编辑:我能够通过运行命令来临时修复它
zip -d spring-android-core-1.0.1.RELEASE.jar META-INF/notice.txt
until all the duplicate errors went away.
直到所有重复的错误消失。
回答by Scott Barta
As of Android Studio version 0.8.14
从 Android Studio 0.8.14 版开始
You should add:
你应该添加:
android {
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude '...'
}
}
to your build.gradle
file.
到您的build.gradle
文件。
History:
历史:
According to comment 14 in this bug: https://issuetracker.google.com/issues/36982149#comment14this is a bug in v0.7.0 of the Android Gradle plugin, and is due to be fixed soon in 0.7.1.
根据此错误中的评论 14:https: //issuetracker.google.com/issues/36982149#comment14,这是 Android Gradle 插件 v0.7.0 中的一个错误,将很快在 0.7.1 中修复。
Here are the notes from that bug about the addition for 0.7.1:
以下是该错误中关于 0.7.1 添加的注释:
0.7.1 is out with the fix for this.
0.7.1 已经解决了这个问题。
The DSL to exclude files is:
排除文件的 DSL 是:
android {
packagingOptions {
exclude 'META-INF/LICENSE.txt'
}
}
You can add as many exclude statement as you want. The value is the archive path. No wildcard or glob support yet.
您可以根据需要添加任意数量的 exclude 语句。该值是存档路径。尚无通配符或 glob 支持。
Filenames "LICENSE.txt" and "NOTICE.txt" are case sensitive. Please try out with "license.txt" and "notice.txt" as well.
文件名“LICENSE.txt”和“NOTICE.txt”区分大小写。请尝试使用“license.txt”和“notice.txt”。
回答by vincentjames501
In my case I had to include several additional exclusions. It appears it doesn't like Regular expressions which would've made this a nice one-liner.
就我而言,我必须包括几个额外的排除项。看起来它不喜欢正则表达式,这会使它成为一个很好的单行。
android {
packagingOptions {
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/dependencies.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/LICENSE'
exclude 'META-INF/license.txt'
exclude 'META-INF/LGPL2.1'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/notice.txt'
}
}
回答by user3121011
packagingOptions {
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
回答by JJD
Have a look at Sakiboy's comment!
看看Sakiboy的评论!
Outdated answer
过时的答案
From Gradle 0.9.1 the following is supported:
从 Gradle 0.9.1 开始,支持以下内容:
android.packagingOptions {
pickFirst 'META-INF/LICENSE.txt'
}
More information in the Gradle release notes.
Gradle 发行说明中的更多信息。
回答by ferdiado
The same problem when I export the library httclient-4.3.5 in Android Studio 0.8.6 I need include this:
当我在 Android Studio 0.8.6 中导出库 httclient-4.3.5 时,同样的问题我需要包括:
packagingOptions{
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
}
The library zip content the next jar:
库 zip 内容下一个 jar:
commons-codec-1.6.jar
commons-logging-1.1.3.jar
fluent-hc-4.3.5.jar
httpclient-4.3.5.jar
httpclient-cache-4.3.5.jar
httpcore-4.3.2.jar
httpmime-4.3.5.jar
回答by Ryan Heitner
This bug still exists in 0.8+/1.10
这个bug在0.8+/1.10仍然存在
With Hymanson
与Hyman逊
compile 'com.fasterxml.Hymanson.dataformat:Hymanson-dataformat-csv:2.2.2'
I had to include as well as the above suggestion before it would compile
在编译之前,我必须包括上面的建议
exclude 'META-INF/services/com.fasterxml.Hymanson.core.JsonFactory'
回答by Pian0_M4n
It's more than one error
错误不止一个
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'
}
}
In case of duplicate files it's easy, look inside the JAR
under the META-INF
dir and see what's causing the error. It could be multiple. In my case Couchbase Lite plugin.
As you add more plugins, you will need more exceptions
如果文件重复很容易,请查看目录JAR
下的内部META-INF
并查看导致错误的原因。它可以是多个。就我而言,Couchbase Lite 插件。随着您添加更多插件,您将需要更多例外
回答by saneryee
The same problem when I used 'org.springframework.android:spring-android-rest-template:2.0.0.M1' in Android Studio 1.0.1. I need include this in build.gradle
当我在 Android Studio 1.0.1 中使用 'org.springframework.android:spring-android-rest-template:2.0.0.M1' 时出现同样的问题。我需要将其包含在build.gradle
android{
...
packagingOptions{
exclude 'META-INF/notice.txt'
exclude 'META-INF/license.txt'
}
...
}
回答by Sestertius
This works for me:
这对我有用:
android {
packagingOptions {
exclude 'LICENSE.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'
}
p.s same answer from my post in : Error :: duplicate files during packaging of APK
ps 与我在以下帖子中的相同答案: 错误 :: 打包 APK 期间的重复文件