How to include a proguard configuration in my Android library (AAR)
In your Gradle file's default configuration closure, specify your Proguard file with consumerProguardFiles
instead of proguardFiles
. For example:
defaultConfig {
consumerProguardFiles 'proguard.txt'
}
ProGuard artefact
[ProGuard workflow]
Artefact not minified, Consumer solve it
Library is open-sourced but as a library developer you can provide a ProGuard file which will be take into account by consumer(app) by demand(minifyEnabled true
in consumer). consumerProguardFiles
in you library build.gradle
. It adds proguard.txt
file(is the same as .pro
) in an artefact
For example your library is open-source and application developer wants to minify all
android {
defaultConfig {
//consumerProguardFiles '<file_path>'
consumerProguardFiles 'proguard-rules.pro'
}
buildTypes {
release {
minifyEnabled false
}
}
//...
}
Artefact is minified
Library is closed-source - you are able to use the next possibility:
android {
buildTypes {
release {
minifyEnabled true
//proguardFiles project(':<project_name>').file('<file_path>')
proguardFiles 'proguard-rules.pro'
}
}
//...
}
*Please note that:
minifyEnabled true
andproguardFiles project
both should be set.- If you use single
minifyEnabled true
or<file_path>
is wrong -classes.jar
is empty. - If single
proguardFiles project
- no effect
As for build process on the example of library - application
- all .class
files will be merged into single archive with .dex
extension