I have a library that will be consumed by apps. This module has interfaces and helper classes.
How can I obfuscate the whole module but still allow access to all those interfaces and helper classes?
I tried this:
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
Then I found myself having to do --keep
on all my classes in proguard. Is there something I can add to pro guard so that I can keep all those interfaces/helper-classes and still have it as obfuscated?
If you want to keep only the public API of your library from being obfuscated, you need to specify this public API. There are various approaches for libraries:
Have separate package for public API and actual implementations, e.g.
com.example.library
contains the public API, whereascom.example.library.internal
contains the actual implementations that are hidden.Make the actual implementations package private
The ProGuard rules would then look like this:
This will keep only public classes together with their public or protected methods / fields in the com.example.library package.