Reputation: 3974
In my gradle file, I have the following:
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE'
}
According to the documentation:
/**
* Adds an excluded paths.
* @param path the path, as packaged in the APK
*/
What does this mean? Could someone give me a real life example of why these exclusions would need to be made?
Upvotes: 28
Views: 26684
Reputation: 24532
For Kotlin DSL (build.gradle.kts) and Android Gradle Plugin (AGP) version 7.0.0 and higher the exclude
method is deprecated in favor of the resources.excludes
property:
android {
// ...
packaging { // or packagingOptions in AGP < 8.x
resources.excludes += "META-INF/LICENSE*"
resources.excludes += "META-INF/NOTICE.txt"
// OR
// resources.excludes += setOf(
// "META-INF/LICENSE*",
// "META-INF/NOTICE.txt"
// )
}
}
Upvotes: 6
Reputation: 11403
If you were to change the extension of a few aar
files to zip
and open them eventually you will have two aar
files with files that with the same path.
SomeDependency-A.aar
-META-INF/LICENSE
...
SomeDependency-B.aar
-META-INF/LICENSE
...
When the aar
dependencies are merged it fails because it tries to add the file LICENSE
and it already exists.
We resolve this by excluding the duplicated files
android {
packagingOptions {
exclude 'META-INF/LICENSE'
}
}
Upvotes: 24