Using Android Gradle plugin 0.7.0 with the following build.gradle
:
buildscript {
repositories {
mavenCentral()
}
dependenci
In my case I only need to add to project's build.gradle file:
android {
packagingOptions {
exclude 'META-INF/notice.txt'
exclude 'META-INF/license.txt'
}
...
}
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{
...
packagingOptions{
exclude 'META-INF/notice.txt'
exclude 'META-INF/license.txt'
}
...
}
The problem is that the META-INF folder won't get filtered so multiple entries of NOTICE
or LICENSE
cause duplicates when building and it is tryed to copy them together.
Dirty Quick Fix:
Open the .jar
file in your .gradle/caches/...
folder (with a zip compatible tool) and remove or rename the files in the META-INF
folder that cause the error (usally NOTICE
or LICENSE
).
(I know thats also in the OP, but for me it was not really clear until I read the google forum)
EDIT:
This was fixed in 0.7.1. Just add the confilcting files to exclude.
android {
packagingOptions {
exclude 'META-INF/LICENSE'
}
}
Same here with
dependencies {
compile 'org.apache.oltu.oauth2:org.apache.oltu.oauth2.client:1.0.0'
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
}
I lost like 2 days for that weird error... Why is this still happening in gradle 1.0.0 ? That is very disturbing for newbies... Anyway, thanks for that info i thought it was on my code :)
Important to know in what file it comes to this error (in you example it is META-INF/LICENSE.txt) , in my case it was in META-INF/LICENSE [without ".txt"], and then in the file META-INF/ASL2.0 so I added to my build.gradle this lines:
android {
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/ASL2.0'
}
}
Very important (!) -> add the name of the file in the same style, that you see it in the error message: the text is case sensitive, and there is a difference between *.txt and *(without "txt").
You should add:
android {
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude '...'
}
}
to your build.gradle
file.
According to comment 14 in this bug: https://issuetracker.google.com/issues/36982149#comment14 this is a bug in v0.7.0 of the Android Gradle plugin, and is due to be fixed soon in 0.7.1.
Here are the notes from that bug about the addition for 0.7.1:
0.7.1 is out with the fix for this.
The DSL to exclude files is:
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.
Filenames "LICENSE.txt" and "NOTICE.txt" are case sensitive. Please try out with "license.txt" and "notice.txt" as well.