Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 700
lostintranslation Avatar asked Jan 02 '18 20:01

lostintranslation


People also ask

How do you keep all classes in ProGuard?

-keepclassmembernames. This is the most permissive keep directive; it lets ProGuard do almost all of its work. Unused classes are removed, the remaining classes are renamed, unused members of those classes are removed, but then the remaining members keep their original names.

Does ProGuard remove unused classes?

ProGuard Facts:Helps to remove unused classes, members & fields. It removes unused codes from your libraries as well. (Which means, any method or field that is not referenced anywhere will be removed by ProGuard Shrinker). Helps to reduce the build size by obfuscating the classes, methods, & fields with short names.

What is keep class in ProGuard?

Specifies classes and class members whose names are to be preserved, if they aren't removed in the shrinking phase. For example, you may want to keep all class names of classes that implement the Serializable interface, so that the processed code remains compatible with any originally serialized classes.

What is R8 ProGuard?

R8 is another tool that will convert your java byte code into an optimized format of dex code. It will check the whole application and will remove the unused classes and methods. It helps us to reduce the size of our APK and to make our app more secure. R8 uses similar proguard rules to modify its default behavior.


1 Answers

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

like image 173
bwt Avatar answered Sep 21 '22 23:09

bwt