Optimize, Shrink, and Obfuscate Your Android App: The 2026 Edition
From ProGuard to R8 Full Mode — how to slash your APK size and keep your code secure in modern Android development.
Optimize, Shrink, and Obfuscate Your Android App: The Modern R8 Guide
From ProGuard to R8 Full Mode — how to slash your APK size and keep your code secure in modern Android development.

It’s been five years since I first wrote about optimizing and shrinking Android apps. Back in 2020, we were talking about enabling ProGuard and basic shrinking. Fast forward to 2026, and the landscape has changed. Apps are getting bigger, but our tools have gotten smarter.
If you are still using the same configurations from 2020, you are missing out on massive free optimizations. Today, we are diving deep into R8 Full Mode, advanced Keep Rules, and how to troubleshoot them without tearing your hair out.
The New Standard: R8 is King
First, a quick refresher: ProGuard is effectively legacy. The Android Gradle Plugin (AGP) now uses R8 by default for everything — shrinking, obfuscating, and optimizing. R8 is faster and produces smaller DEX files because it combines the shrinking and dexing steps into one.
But here is the catch: many developers just turn it on and forget it. To get the real space savings, you need to configure it correctly.
1. Enable R8 Full Mode
In the past, R8 operated in “Compatibility Mode” to mimic ProGuard, which was safer but less efficient. Since AGP 8.0, R8 Full Mode is the default. It performs aggressive optimizations like changing class visibility, inlining methods, and removing unused interfaces.
Check your gradle.properties. If you see this line, delete it immediately:
# DELETE THIS LINE to get better shrinking!
android.enableR8.fullMode=false
By ensuring Full Mode is active, R8 can rewrite your code to be as small as theoretically possible.
2. The Secret Sauce: proguard-android-optimize.txt
Most tutorials tell you to use the default configuration file. But look closely at your build.gradle.kts:
buildTypes {
getByName("release") {
isMinifyEnabled = true
isShrinkResources = true
// TRICK: Use 'optimize' version, not just 'proguard-android.txt'
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
Using proguard-android-optimize.txt enables extra optimizations at the bytecode level that the standard file skips.
3. Mastering Keep Rules (The Tricky Part)
This is where 90% of developers get stuck. R8 is a static analysis tool — it looks at your code and removes anything that doesn’t seem to be used. But what about Reflection or JNI? R8 can’t see those dynamic calls, so it might delete code your app actually needs, causing crashes.
To fix this, we use Keep Rules. But be careful!
The Anti-Pattern (Don’t do this):
# BAD PRACTICE: This keeps EVERYTHING in the package, defeating R8's purpose.
-keep class com.example.mydata.** { *; }
The Best Practice: According to the latest Android Developers Guide, you should write narrow rules. Only keep exactly what is needed. Even better, allow R8 to still shrink or obfuscate parts of the class you are keeping.
# GOOD PRACTICE: Keep the class, but allow R8 to shrink unused members
# and obfuscate the name if possible.
-keep,allowshrinking,allowobfuscation class com.example.mydata.User
Better yet, use the @Keep annotation directly in your Kotlin code. It’s cleaner and keeps the rule right next to the code it affects.
@Keep
data class User(val id: String, val name: String)
4. Slash Resource Sizes
Code isn’t the only thing bloating your APK. Resources (images, layouts) often take up the most space.
- Remove Unused Resources:
isShrinkResources = trueis a must. - Language Splitting: If your app doesn’t support French or German, why include the Android framework strings for them?
defaultConfig {
// Only keep resources for English and your specific supported languages
resourceConfigurations += setOf("en", "hi")
}
- Convert to WebP: Right-click your PNGs in Android Studio and select “Convert to WebP”. It can reduce image size by up to 90% with zero quality loss.

(Screenshot of the “Convert to WebP” dialog in Android Studio showing a 2% saved size result)
5. App Bundles are Non-Negotiable
If you are still uploading .apk files to the Play Store, stop! Uploading an Android App Bundle (.aab) lets Google Play generate optimized APKs for each user's device. A user on a low-end phone won't download your high-res xxxhdpi assets. This alone can reduce download size by 15-20%.
Summary
Optimization is a continuous battle.
- Enable R8 Full Mode (and don’t disable it!).
- Use
**proguard-android-optimize.txt**. - Write specific Keep Rules (avoid wildcards).
- Audit your resources regularly.
Your users (and their data plans) will thank you.
References
Happy Shrinking! :)
메타데이터
- post_id
- a33f79f2ea1d
- slug
- optimize-shrink-and-obfuscate-your-android-app-the-2025-edition-a33f79f2ea1d
- url
- https://proandroiddev.com/optimize-shrink-and-obfuscate-your-android-app-the-2025-edition-a33f79f2ea1d
- canonical_url
- https://proandroiddev.com/optimize-shrink-and-obfuscate-your-android-app-the-2025-edition-a33f79f2ea1d
- author_url
- https://medium.com/@jaypatelbond
- status
- ok
- fetched_at
- 2026-06-12 10:20:10