'Gradle android optimize packagingOptions
I have that project structure:
-gradle root
|-clients
|-client 1
|-client 2
...
|-client N
|-libs
|-android lib 1
|-android lib 2
...
|-android lib N
|-java lib 1
|-java lib 2
...
|-java lib N
In each client build file I have the packagingOptions to exclude options.
Something like that:
packagingOptions {
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
}
How could I optimize that block and move it for example in my root gradle build file? I don't really want to copy paste it across all clients.
Solution 1:[1]
Found solution. Credits: https://github.com/frankdu/android-gradle-dagger-tutorial
I've created separate build file and moved that settings there. File android_common.gradle
android {
packagingOptions {
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
}
}
Then in each client put that line:
apply from: "${rootDir}/android_common.gradle"
And finally excluded packagingOptions from my clients build files.
In additional I've moved another common configurations there.
Looks clean, simple and nice after that.
Solution 2:[2]
For the record, most of your package options are already the default.
See PackagingOptions Gradle documentation
Pick first: none
Merge: /META-INF/services/**
Exclude:
/META-INF/LICENSE
/META-INF/LICENSE.txt
/META-INF/NOTICE
/META-INF/NOTICE.txt
/LICENSE
/LICENSE.txt
/NOTICE
/NOTICE.txt
/META-INF/*.DSA (all DSA signature files)
/META-INF/*.EC (all EC signature files)
/META-INF/*.SF (all signature files)
/META-INF/*.RSA (all RSA signature files)
/META-INF/maven/** (all files in the maven meta inf directory)
/META-INF/proguard/* (all files in the proguard meta inf directory)
**/.svn/** (all .svn directory contents)
**/CVS/** (all CVS directory contents)
**/SCCS/** (all SCCS directory contents)
**/.* (all UNIX hidden files)
**/.*/** (all contents of UNIX hidden directories)
**/*~ (temporary files)
**/thumbs.db
**/picasa.ini
**/protobuf.meta
**/about.html
**/package.html
**/overview.html
**/_*
**/_*/**
Solution 3:[3]
For those who cant find fresh documentation link for PackagingOptions.
This must be comment to LanDenLabs answer but I cant post a comment without 50 rep :(
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Shubham Suryavanshi |
| Solution 2 | LanDenLabs |
| Solution 3 | iddqdpwn |
