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.
ProGuard is a tool to help minify, obfuscate, and optimize your code. It is not only especially useful for reducing the overall size of your Android application as well as removing unused classes and methods that contribute towards the intrinsic 64k method limit of Android applications.
Android Studio adds the proguard-rules.pro file at the root of the module, so you can also easily add custom ProGuard rules specific to the current module. You can also add ProGuard files to the getDefaultProguardFile directive for all release builds or as part of the productFlavor settings in the build.
When you create a new project or module using Android Studio, the IDE creates a <module-dir>/proguard-rules.pro file for you to include your own rules. You can also include additional rules from other files by adding them to the proguardFiles property in your module's build. gradle file.
minify is an Android tool that will decrease the size of your application when you go to build it. It's extremely useful as it means smaller apk files! It detects any code or libraries that aren't being used and ignores them from your final apk.
I would try to answer each questions, even though let me know if something doesn't make sense!
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.
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.)
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...
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!
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