Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 926
Redwid Avatar asked Jul 29 '14 12:07

Redwid


People also ask

What is Packagingoptions in Gradle?

The list of patterns where all occurrences are concatenated and packaged in the APK. The list of patterns where the first occurrence is packaged in the APK.

What is Packagingoptions in Android Studio?

DSL object for configuring APK packaging options. Packaging options are configured with three sets of paths: first-picks, merges and excludes: First-pick. Paths that match a first-pick pattern will be selected into the APK.


2 Answers

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.

like image 147
Redwid Avatar answered Oct 20 '22 21:10

Redwid


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
**/_*
**/_*/**
like image 37
LanDenLabs Avatar answered Oct 20 '22 22:10

LanDenLabs