Member-only story
Using Proguard and R8 for optimizing Android apps
Providing a great user experience starts with the way we write our code. Using clean code techniques and avoiding unnecessary dependencies are absolute musts if we want to minimize the noise in our codebase.
However, we might sometimes miss some classes or some resources that end up going unused. Not to mention that when we add libraries to our projects, we often only make use of about ten percent of what they have to offer.
All of these will add up — and in the end, they result in a large bundle that might even discourage users from downloading our app. A smaller app size not only makes the download and installation process faster for users, but also takes up less storage space on their devices.
Code shrinkers
There are some powerful tools we can leverage to keep only the code and resources that we actually need in the project, as well as optimize our dependencies and obfuscate the code for security purposes. One such tool is R8, and it has been the default code shrinker in Android Studio for a couple of years.
As per the official docs, if you are using a version newer than 3.4.0 of the Gradle plugin, R8 is used instead of Proguard. Given that the newest Gradle version is 7.4.0 (at the time of writing), we can safely assume that most projects will now use R8. To make the transition from ProGuard to R8 as simple as possible, R8 still uses the same syntax of specifying obfuscation rules via ProGuard files…