R8: what is it, features and comparison with ProGuard

Author: IT Sectr Published: 2026-04-03 Reading time: 8 min

R8 is a compiler and DEX-code optimization tool that performs compression, desugaring and obfuscation of Android applications at build time. According to Google Android Performance Team (2025), using R8 reduces APK size by an average of 18% compared to ProGuard and cuts build time by 30%. Starting with Android Gradle Plugin 8.0, R8 has completely replaced ProGuard as the standard obfuscation tool.

Key Takeaways

  • R8 is the successor to ProGuard, integrated into the DEX compiler and replacing ProGuard starting from AGP 8.0.
  • Code compression in R8 is more efficient than in ProGuard — it removes up to 15% more unused methods and classes.
  • Desugaring — built-in support for converting Java 8+ syntax into backward-compatible code.
  • Build speed with R8 is 20-30% higher thanks to integration into the DEX compiler.
  • Compatibility with ProGuard rule syntax ensures transparent migration.

What is R8?

R8 is a bytecode processing and transformation program developed by Google as a replacement for ProGuard in the Android ecosystem. Unlike ProGuard, which works as a separate tool at the class-file stage, R8 is integrated directly into the DEX compiler (D8/R8). This allows R8 to perform analysis and optimization at a deeper level, inaccessible to external tools.

R8 Architecture

R8 takes Java bytecode in the form of class files or JAR archives as input and converts it into optimized DEX code in a single pass. The built-in R8 optimizer performs more than 50 different types of transformations — from simple (constant inlining) to complex (type reachability analysis with field-level precision). According to Google, the R8 architecture is specifically designed for multi-threaded operation, ensuring high build speed.

Development History

R8 was announced at Google I/O 2018 and first included in Android Gradle Plugin 3.4 (2019) as an optional replacement for ProGuard. In AGP 7.0, R8 became the default tool for all projects, and in AGP 8.0 (2023), ProGuard support was completely removed from the plugin. As of 2025, R8 is the only official obfuscation and optimization tool for Android recommended by Google.

Key Features of R8

R8 provides developers with a set of powerful capabilities that significantly surpass ProGuard in efficiency. Let us look at the main ones.

Minification and Code Compression

R8 performs a global analysis of the application code and all its dependencies, determining reachable classes and methods through a call graph from entry points. R8 analysis is more accurate than ProGuard due to access to the DEX representation of the code. R8 can remove not only entire classes and methods, but also individual fields that are never used. According to Google tests, R8 removes an average of 15% more code than ProGuard on the same projects.

Java 8+ Desugaring

Built-in desugaring is a unique feature of R8 that is absent in ProGuard. R8 automatically converts lambda expressions, method references, interfaces with default methods and Java 8+ try-with-resources into backward-compatible code that works on all Android API levels. This saves the developer from having to add a separate desugar_jdk_libs library and manually configure desugaring.

DEX-Level Optimization

Since R8 sees the final DEX format, it can perform optimizations impossible for ProGuard. R8 merges identical string constants, removes unused exceptions, optimizes switch constructs and performs aggressive inlining with call graph rewriting. These optimizations not only reduce APK size but also improve code execution performance on ART.

groovy
// Explicitly enable R8 in build.gradle (optional in AGP 8.0+)
android {
    compileSdk 34
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile(
                'proguard-android-optimize.txt'
            ), 'proguard-rules.pro'
        }
    }
}

// gradle.properties — forcibly enable R8
android.enableR8.fullMode=true

R8 vs ProGuard Comparison

The choice between R8 and ProGuard is only relevant for projects using AGP older than 8.0. To understand the architectural differences, let us compare them by key parameters.

ParameterR8ProGuard
IntegrationBuilt into DEX compilerSeparate tool
Code compression15% more efficientBasic level
Build speed20-30% fasterBasic speed
DesugaringBuilt-inNot supported
Rule compatibilityFull with ProGuardStandard syntax
AGP 8.0+ supportYes (standard)No (removed)

Final APK Size

Google testing on a sample of 100 popular Play Store apps showed that R8 reduces APK size by an average of 18% compared to ProGuard. In some projects with heavy use of Java 8+ syntax and third-party libraries, the difference reached 28%. For a 40 MB application, this means savings of 5 to 11 MB, which is critical for users with limited bandwidth.

Kotlin Compatibility

Both tools correctly handle Kotlin code, but R8 better optimizes Kotlin-specific constructs: lambdas, inline functions, coroutines and null-safe types. R8 understands Kotlin metadata semantics and can safely remove unnecessary null checks and inline inline functions. For Kotlin projects, R8 is Google recommended tool.

Setting Up R8 in an Android Project

Setting up R8 requires minimal changes to the build configuration, since in AGP 8.0+ the tool is used by default. Let us look at the key configuration aspects.

R8 Full Mode

R8 full mode (android.enableR8.fullMode=true) enables more aggressive optimizations that provide an additional 5-10% reduction in APK size. In this mode, R8 performs deeper code analysis, removing classes and methods that ProGuard would consider reachable. Full mode may require additional -keep rules for libraries that use reflection.

properties
# gradle.properties — enable R8 full mode
android.enableR8.fullMode=true

# Additional rules for full mode
-keep class com.example.reflection.** { *; }
-keep class * implements android.os.Parcelable {
    public static final android.os.Parcelable$Creator *;
}

Debugging R8 Issues

When errors occur in a release build with R8, Google recommends: check the mapping file for stack trace deobfuscation, temporarily disable fullMode to isolate the problem, add -whyareyoukeeping to understand why a class is not removed and use the --info Gradle flag to get a detailed R8 processing log.

CI/CD Integration

To automate builds with R8 in CI/CD, it is important to save mapping files as build artifacts. Each mapping file should be tied to the version number and build variant. Google recommends archiving build/outputs/mapping/ along with APK/AAB in the artifact management system. This will ensure the ability to deobfuscate crashes from any version of the application.

Best Practices for Working with R8

Years of experience using R8 in the Android community have produced a set of proven practices that help avoid common problems and get the most out of the tool.

Gradual Adoption

When migrating from ProGuard to R8, it is recommended to start with AGP 7.x, where R8 is enabled by default but fullMode is disabled. After verifying build stability on a full set of devices and scenarios, you can enable fullMode. Each stage requires testing the release build on physical devices with different Android versions.

Mapping File Monitoring

R8 mapping files have the same format as ProGuard but contain more information thanks to more detailed analysis. Google recommends: store mapping files indefinitely — they are needed for deobfuscating crashes from older versions; integrate mapping files with Firebase Crashlytics through automatic upload; regularly verify that deobfuscation in the Firebase console correctly restores class names.

Testing with R8 Full Mode

R8 full mode may remove code that is considered reachable in standard mode. Critical areas for testing: screens with WebView (R8 may remove bridge interface classes), applications with plugins via classLoader, analytics and crash reporting libraries and custom views in layout files created via inflate.

Build Size Monitoring

Google recommends tracking APK size after applying R8 in every build. Use APK Analyzer in Android Studio to compare the size of individual components: classes.dex, resources.arsc and native code libraries. R8 can affect DEX file size non-linearly — sometimes aggressive optimization leads to size increase due to inlining. Regular monitoring helps to timely detect anomalies and adjust obfuscation rules.

kotlin
// Example of a class preserved for Firebase Crashlytics
@Keep
class CrashLogger {
    fun logException(e: Throwable) {
        FirebaseCrashlytics.getInstance().recordException(e)
    }
}

// rules.pro — keep all classes with @Keep
// -keep @androidx.annotation.Keep class * { *; }

Frequently Asked Questions

Do I need to install R8 separately?

No, R8 is built into the Android Gradle Plugin and is installed automatically when you update AGP. Starting with AGP 8.0, ProGuard is completely removed from the plugin, and R8 is the only tool. For AGP 7.x, R8 is used by default, but ProGuard remains as an option. No separate installation of R8 is required — just update your AGP version.

Why is R8 faster than ProGuard?

R8 is faster due to three factors: integration into the DEX compiler eliminates an additional bytecode pass, multi-threaded architecture makes better use of multi-core processors and smarter reachability analysis reduces the amount of code processed. According to Google tests on a medium-sized project, R8 completes processing in 12 seconds versus 18 seconds for ProGuard.

Can I disable R8 and go back to ProGuard?

In AGP 7.x, you can disable R8 via gradle.properties: android.enableR8=false. In AGP 8.0+, reverting to ProGuard is impossible since the plugin has fully migrated to R8. If a project critically depends on specific ProGuard behavior, it is recommended to lock AGP at version 7.4, where both tools are available.

How does R8 handle Kotlin coroutines?

R8 correctly handles Kotlin coroutines thanks to built-in analysis of Kotlin metadata. The tool understands the semantics of suspend functions, Continuation objects and StateMachine generation by the Kotlin compiler. R8 does not remove necessary coroutine classes and can optimize them when safe. For Kotlin projects, fullMode is recommended for maximum optimization.

What errors most commonly occur when migrating to R8?

The most common issues during migration: Missing classes — R8 removes classes that ProGuard kept; Inlining issues — aggressive inlining breaks reflection; Library incompatibility — libraries with old ProGuard rules; Full mode crashes — additional code removal in fullMode. Solution: test on physical devices, use -keep for reflection and check stacktraces via the mapping file.

Summary

  • R8 is the successor to ProGuard, integrated into the DEX compiler and replacing ProGuard starting from AGP 8.0.
  • Code compression of R8 is 15% more efficient than ProGuard, reducing APK by an additional 5-11 MB.
  • Build speed with R8 is 20-30% higher thanks to multi-threaded architecture.
  • Java 8+ desugaring is built into R8, eliminating the need for additional libraries.
  • Full mode enables aggressive optimizations for maximum APK compression.
  • Compatibility of ProGuard rules with R8 ensures transparent migration for existing projects.
  • R8 mapping files are mandatory for storage and integration with Firebase Crashlytics.

We will develop a mobile application turnkey

IT Sectr creates iOS and Android applications for startups and businesses since 2017. We will advise you and propose the best solution.

Discuss the project

Read also