TLDR: How to pass proguard mapping to javac to compile against obfuscated library ?
That's long, but I don't see how to make it shorter:
Background: I have the following product setup:
Android Studio project - Library module - (sub)module Core - (sub)module A - (sub)module B - (sub)module C - Sample App module - ... Other modules
Each of library submodules A, B, C reference classes in Core, but A, B, C independent among themselves. Conceptually similar to Play Services where user can only have code and required sub-module. Each of the library submodules has external APIs but also many internal classes The goal is to be able to distribute Core, A, B, C as independent aar-s.
Goal: obfuscate all sub-modules together leaving only public APIs exposed but package and distribute them separately in obfuscated/optimized form.
Issue: I do not see how to use it with straightforward gradle configuration. Custom build system is needed here, Unless there is a any known solution?
What is needed here is:
Where is normal build process is for each module is: - Compile -> do everything incl. obfuscation -> package
Straight forward setup fails at the compilation of the first submodule after Core. If it only would be possible to pass Proguard mapping.txt as an input to Java compiler... But I could not find such an option. Any ideas?
Thanks!!!
Issue: I do not see how to use it with straightforward gradle configuration. Custom build system is needed here, Unless there is a any known solution?
So, you're looking for a "custom build system" since you don't know how to do it in gradle. But if this could be solved in gradle, you'd like to use it, right?
To proguarding libraries with gradle, you have 2 options:
minifyEnabled true
, and use proguardFiles
function to set your proguard.txt file.minifyEnabled false
, and use consumerProguardFiles
function to pass the proguard.txt file from each library to the main module.Here is explained in detail with code examples, so I'm not going to replicate the answer: https://stackoverflow.com/a/42758629/1516973
I've had the same problem, and I've written this post on my personal website.
In essence, what you are looking for is the maven-publish
Gradle plugin, that will allow you to package your library modules to AAR and conveniently manage and distribute them, while retaining the information on their dependencies.
You can configure this plugin to package a specific buildType
for which you will enable proguard obfuscation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With