I have create a module in Android to use in my main app and there seem to be two of these files consumer-rules.pro and proguard-rules.pro.
I would like to know the folllowing things
Please advise.
I'll try to answer each question, but let me know if something doesn't make sense!
1. Will all of the modules code be obfuscated by the rules of the main modules pro-guard rules even if the module does not specify any rules?
Obfuscation doesn't work that way. When you enable the minifyEnabled
property in your app module, it tries to obfuscate code available from the app module as well as its 3rd party dependencies, and your library modules would be considered 3rd party deps. But it doesn't touch any transitive dependency of your 3rd party dependencies.
2. What is the difference between consumer-rules.pro and proguard-rules.pro in Android?
proguard-rules.pro is the file where you declare rules related to Proguard for your module and its dependencies.
consumer-rules.pro is the file where you declare rules that can be applied to your module by the consumer (whoever would be using your module/library as a dependency -- typically library devs).
3. Should i enable minifyEnabled in my module?
I would suggest that you do (Every dev should on release APKs), but make sure everything is working as expected because the underlying classes.dex changes after applying minifyEnabled
. It helps reduce output APK size, optimizes code, obfuscates class files, and much more...
4. I noticed that i can add proguard rules for my module in the main module , so does that mean pro-guard rules in the module are overriden in the main module?
No, basically library rules get applied from the consumer-rules file from the library module itself, so when you declare those rules for the library in the app module, it gets applied the same way from consumer-rules, which is basically an indication that the consumer should use these rules when minifying.
proguard-rules.pro of the library is the place where you declare rules for 3rd party dependencies of your library (which is considered a transitive dependency for your app module/main module), and it doesn't get overridden by app module rules.
I hope that makes sense!