Search code examples
androidandroid-proguardaar

Proguard not keeping classes when building aar


From this reference:

https://github.com/codepath/android_guides/wiki/Building-your-own-Android-library

I have the following gradle file:

android {
    compileSdkVersion 25
    buildToolsVersion "26.0.2"

    buildTypes {
        release {
            minifyEnabled true
            consumerProguardFiles 'consumer-proguard-rules.pro'
        }
    }
}

And the following proguard file:

-dontobfuscate
-optimizations !code/allocation/variable

-keep public class * {
    public protected *;
}

However all of my classes in the aar are missing when I run the 'assembleRelease' task to build my release aar file.

Any ideas?


Solution

  • You should set minifyEnabled to false (the default value) : consumerProguardFiles is not used for immediate minification (i.e. when building the library itself). It it used when the consumer of the library (e.g. an application) is build.

    Minifying the library before consumption is not recommended, because you can not know what parts will actually be used before the final build. Libraries usually don't do it. e.g. LeakCanary, ACRA, Butter Knife