ProGuard — Everything You Need to Know

What is ProGuard? Why do we use it?

Attila
10 min readSep 18, 2023

To make your Android app smaller, enable shrinking in the release build. Shrinking, using R8, removes unused code and resources, offers obfuscation to shorten class names, and applies optimization. The Android Gradle plugin (v3.4.0+) uses R8 instead of ProGuard for these tasks. It performs:

  1. Code Shrinking: Detects and safely removes unused code from your app and its libraries, helpful for avoiding the 64k reference limit.
  2. Resource Shrinking: Removes unused resources from your app, working in tandem with code shrinking.
  3. Obfuscation: Shortens class and member names, reducing DEX file sizes.
  4. Optimization: Analyzes and optimizes your code further.

When building the release version, R8 can handle these tasks, and you can customize its behavior through ProGuard rules if needed without changing your existing rules.

Configuration in the Android project

When using Android Studio 3.4 or Android Gradle plugin 3.4.0 and newer versions, R8 is the default compiler for converting Java bytecode to Android’s DEX format. However, when creating a new project in Android Studio, shrinking, obfuscation, and code optimization are not enabled by default. This is because these optimizations can increase build times and potentially introduce bugs if not customized properly.

--

--