Search code examples
androidgradleproguardaar

How to include a proguard configuration in my Android library (AAR)


Android libraries, per the AAR file spec, includes a 'proguard.txt' file. My understanding is that this file declares how the library correctly can be obfuscated and minified. In my case I need to preserve some API-classes.

How can I declare the library's proguard.txt file in the library's build.gradle? And will this file be automatically read when creating an application (APK) that uses my library?

I didn't find this information in Android's Gradle Plugin User Guide.


Solution

  • In your Gradle file's default configuration closure, specify your Proguard file with consumerProguardFiles instead of proguardFiles. For example:

    defaultConfig {
        consumerProguardFiles 'proguard.txt'
    }