Issue
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
- 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?
- What is the difference between consumer-rules.pro and proguard-rules.pro in Android?
- Should i enable minifyEnabled in my module?
- 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?
Please advise.
Solution
I would try to answer each questions, even though 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 minify property in your app module it tries to obfuscate code available from app module as well as it's 3rd party dependencies & your library modules would be considered as 3rd party deps. here, but it doesn't touches any transitive dependency of your 3rd party dependency.
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 to related to proguard for you module & it's dependencies.
consumer-rules.pro is the file where you declare rules that can be applied on your module from consumer (whoever would be using your module/library as dependency, usually used by library devs.)
3. Should i enable minifyEnabled in my module?
I would suggest that you should (Every dev must do on release apk), but make sure everything is working as expected because underlying classes.dex changes after applying minify. It helps reducing output apk size, optimizes code, obfuscate 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 rule gets applied from consumer-rules file from library module itself, so when you declare those rules for library in app module it gets applied the same way from consumer-rules which is basically indication that consumer should use these rules when minifying.
proguard-rules.pro of library is the place where you declare rules for 3rd party dependencies of your library (Which is considered as transitive dependency for your app module/main module) & it doesn't get overridden by app module rules.
I hope that makes sense!
Answered By - Jeel Vankhede
Answer Checked By - Dawn Plyler (JavaFixing Volunteer)