Generated banner for R8 Analyzer
Generated logo for R8 Analyzer

R8 Analyzer

Android (Google)OfficialCreated by Google LLCDistributed by Android (Google)

  • Skill
  • Review and audit
  • Software development
  • Apache-2.0
  • Low risk
  • Has scripts

From the author

Analyzes Android build files and R8 keep rules to identify redundancies, broad package-wide rules, and rules that subsume library consumer keep rules. Use this skill when developers want to optimize their Android app's size, remove redundant or overly broad keep rules, or troubleshoot ProGuard configurations. Don't use for general Gradle build errors, Compose UI performance, or runtime CPU profiling.
— the description by Google LLC

AutoGineer summary

Written by AutoGineer from the skill’s own files, not by the author

The r8-analyzer skill provides a structured approach to auditing Android ProGuard and R8 keep rules. By analyzing build configurations and generating reports on rule impact, it helps developers identify redundant or overly broad rules that negatively affect app size and obfuscation efficiency. The skill supports both modern AGP 9.3+ workflows via standalone tasks and legacy configurations through temporary R8 version updates, ensuring comprehensive coverage for various project setups.

What it does

  • Identifies redundant or overly broad R8 keep rules.
  • Detects rules that subsume library consumer keep rules.
  • Generates impact metrics and scores for existing keep rules.
  • Validates build configuration settings for optimal R8 usage.
  • Provides actionable remediation guidance based on rule patterns.
  • Supports automated report generation for release build variants.

When to use it

  • When you need to reduce the final size of your Android application.
  • When troubleshooting unexpected behavior in ProGuard or R8 configurations.
  • When you suspect that your keep rules are too broad or redundant.
  • When auditing library dependencies for inefficient keep rule declarations.

Advantages

  • Provides quantitative impact metrics for specific keep rules.
  • Automates the extraction and analysis of complex R8 configuration data.
  • Offers clear, standardized reporting formats for build optimizations.
  • Helps maintain cleaner and more efficient ProGuard configuration files.

Usage examples

“Analyze my app's R8 configuration to find redundant keep rules.”
The agent will inspect your build files, run the appropriate R8 analysis task, and generate a report detailing high-impact and redundant rules.
“Why is my Android app size larger than expected? Check my keep rules.”
The agent will perform a deep dive into your R8 rules to identify if overly broad rules are preventing effective code shrinking.

Install

  1. Download the skill as a ZIP:

    https://autogineer.com/agent-skills/android/r8-analyzer/download
  2. Unzip it into the cross-client skills folder of your project:

    mkdir -p .agents/skills && unzip r8-analyzer.zip -d .agents/skills

Documentation by Google LLC

Step 1. Setup and configuration check

  • Inspect build.gradle, build.gradle.kts, and gradle.properties.

  • Use references/CONFIGURATION.md to identify missing optimizations.

  • AGP : If the version is lower than 9.3, suggest migration to 9.3 for the simplified optimization {} DSL and the Configuration Analyzer task.

  • Full mode : Verify android.enableR8.fullMode=false is removed from the gradle.properties file.

Step 2. Analysis path selection

  • Inspect build.gradle, build.gradle.kts, settings.gradle, settings.gradle.kts, gradle.properties, and libs.versions.toml to get the AGP and R8 versions. An R8 version pinned in settings.gradle(.kts) replaces the R8 bundled with AGP.

  • Find the app module (usually app) and a build variant with R8 enabled (usually release). The following commands use them as <module> and <Variant>, for example :app:minifyReleaseWithR8.

  • The helper scripts are in this skill's scripts/ directory. In the following commands, <skill_dir> is this skill's directory. Run every command from the project root.

  • If AGP >= 9.3.0 : Proceed to Path A (Standalone Task).

  • If AGP < 9.3.0 : Proceed to Path B (Quantitative).

Path A: Standalone Gradle task (AGP >= 9.3.0)
  • Step 1: Check requirements : Python and the protobuf package 6.33.4 or later are mandatory (used by scripts/keep_radius_pb2.py). Install it with pip install "protobuf>=6.33.4"; versions lower than 6.33.4 fail on import with a VersionError or ImportError.

  • Step 2: Run standalone task on R8-enabled build : For the module and variant you found during path selection, run ./gradlew :<module>:analyze<Variant>R8Config (for example, ./gradlew :app:analyzeReleaseR8Config). It generates the report in <module>/build/reports/r8/ (for example, app/build/reports/r8/r8-config-analyzer-release.pb). You must wait for this command to finish before proceeding.

  • Step 3: Convert to JSON : You must explicitly run the conversion script scripts/convert_pb_to_json.py as python3 <skill_dir>/scripts/convert_pb_to_json.py with arguments <module>/build/reports/r8 and tmp/keepradius/keepruleradius.json. Wait for this command to finish.

  • Step 4: Analyze : You must explicitly run the analysis script scripts/analyze.py by executing python3 <skill_dir>/scripts/analyze.py tmp/keepradius/keepruleradius.json. This outputs tmp/keepradius/analysis_result.txt. Wait for this command to finish.

Path B: Invoke R8 release build (AGP < 9.3.0)
  • Step 1: Check requirements : Python and the protobuf package 6.33.4 or later are mandatory: pip install "protobuf>=6.33.4".

  • Step 2: Generate and analyze : You must run the shell commands described in references/FULL_BUILD_CONFIG_ANALYZER.md to temporarily update the R8 version in settings.gradle(.kts) to 9.4.34 or later (so R8 generates the report), generate the proto report in tmp/r8analysis/, convert it to tmp/r8analysis/keepruleradius.json, analyze the result, and revert the temporary settings.gradle(.kts) change.

  • Step 3: Analyze : Verify that the analysis outputs tmp/r8analysis/analysis_result.txt for scores and rule impact metrics.

Step 3. Report generation

  • Format : Follow references/REPORT_FORMAT.md strictly.

  • Redundant rules : Check keep rules against references/INSPECT-RULES.md. If a keep rule matches a pattern in references/INSPECT-RULES.md, include the guidance and remediation from that reference alongside the impact metrics.

  • Input : Extract metrics (Scores, Impacts, Example Classes, rule origins) directly from the generated file tmp/keepradius/analysis_result.txt if using Path A, or tmp/r8analysis/analysis_result.txt if using Path B.

  • Output : Short progress updates are fine while Gradle runs; the final message is the report only. Output only the raw Markdown report in the chat. Do not output conversational filler (for example, "Here is your report..."). Do not provide recommendations, next steps, or any other text outside of the sections defined in references/REPORT_FORMAT.md. Do not mention the path used for analysis of the configuration.

Constraints

  • Strict output limit: The final output must strictly be the Markdown report and nothing else.

  • No code changes : Research and suggest only; do not modify project files. Create files only under tmp/ (analysis output, the settings backup, and any scratch scripts), and never write the report to a file. The one exception is the temporary R8 classpath in settings.gradle(.kts) that Path B needs when the project doesn't already pin R8 9.4.34 or later: ask the user first when running interactively, and revert it after the analysis (see references/FULL_BUILD_CONFIG_ANALYZER.md). If that change is needed but the user says no, or asks you not to edit build files, report rule-level and build file findings without scores and say why.

  • No placeholder scores : Never print N/A% as a score.

  • No redundancy: Do not explain R8 benefits or reference skill internal files in the report.

  • Focus: Omit sections (for example, Subsumed Rules, Configuration) if no issues or items are found.

Files

references/INSPECT-RULES.md

This document outlines common "bad" or redundant keep rules for standard Android development and popular libraries. Current Android toolchains and libraries include their own consumer keep rules embedded in their AAR or JAR files, making many manual configurations unnecessary or even harmful to code optimization.

Case: Global keep rules

Common mistakes:

-dontshrink
-dontobfuscate
-dontoptimize
-keep class !com.example.** { *; }

The fix : Global disable flags (-dontshrink, -dontobfuscate, -dontoptimize) and negated keep rules using the ! inversion operator (for example, -keep class !com.example.ui.** { *; }, which matches every class in the app and libraries except the specified package) disable R8 optimizations across the entire codebase. They must be removed from the codebase (or replaced with narrow keep rules for specific classes).

Case: Android components

Keep rules for Android components like Activity, Fragment, ViewModel, Views, Services, or Broadcast receivers are usually redundant. AAPT2 only generates keep rules for components declared in the AndroidManifest.xml and classes referenced from XML resources (layouts, menus, navigation graphs). ViewModels, and Fragments or Views created only in code, aren't covered by AAPT2, but they usually don't need manual rules either: the AndroidX libraries ship the rules they need for reflection.

Common mistakes:

-keep public class * extends android.app.Activity
-keep public class * extends android.app.Service
-keep public class * extends android.view.View
-keepclassmembers class * extends android.app.Fragment { public void *(android.view.View); }

The fix: Delete these manual rules. AAPT2 covers manifest components and classes referenced from XML; other classes need a rule only if something reflects on them.

Case: Official Android and Kotlin libraries

Keep rules targeting official library packages like AndroidX, Kotlin, and Kotlinx are redundant as they are bundled within the libraries themselves. Manual rules are often broader than what is strictly needed.

Common mistakes:

-keep class androidx.** { *; }
-keep class kotlinx.** { *; }
-keep class kotlin.** { *; }

The fix: Delete these manual rules. Rely on the consumer keep rules packaged within these dependencies.

Case: Gson

Overly broad data model rules

The most common mistake is keeping entire packages of data models (POJOs or DTOs). Package-wide model rules are usually unnecessary on Gson 2.11 and higher when the serialized fields use @SerializedName, because Gson's bundled keep rules (from 2.11) keep those fields. On Gson versions lower than 2.11, upgrade first, then remove them. If a class has no no-args constructor, keep a narrow rule for it.

-keep class com.example.app.models.** { *; }
-keep class com.example.app.package.models.* { *; }
Redundant interface and adapter rules

These rules added for TypeAdapter are unnecessary, are already covered by the library, and prevent R8 from effectively shrinking and optimizing custom adapters. R8 determines if the adapter implementations are used. Keeping them globally prevents the removal of unused adapter implementations.

-keep class * extends com.google.gson.TypeAdapter
-keep class * implements com.google.gson.TypeAdapterFactory
-keep class * implements com.google.gson.JsonSerializer
-keep class * implements com.google.gson.JsonDeserializer
Unnecessary TypeToken rules

There is no need to handle generic type erasure; Gson's own rules handle the necessary TypeToken preservation.

-keep class com.google.gson.reflect.TypeToken { *; }
-keep class * extends com.google.gson.reflect.TypeToken
-keep,allowobfuscation,allowshrinking class com.google.gson.reflect.TypeToken
Internal and example packages

Keeping internal library logic prevents the compiler from stripping away dead code within the library.

-keep class com.google.gson.internal.** { *; }
-keep class com.google.gson.internal.reflect.** { *; }
-keep class com.google.gson.internal.UnsafeAllocator { *; }
-keep class com.google.gson.stream.** { *; }
  • Keeps unused code: Prevents R8 from removing models that are never actually used in the code.

  • Prevents method stripping : Keeps all getters, setters, toString, equals, and hashCode methods, even if they are never called.

  • Blocks obfuscation : Prevents the class names from being obfuscated, which is unnecessary for Gson if you use @SerializedName.

The fix:

  1. Use @SerializedName on fields in your data classes that are used for serialization and deserialization.

  2. Gson (2.11.0 and higher ) bundles its own rules (View Gson's embedded ProGuard rules). The bundled keep rules retain the @SerializedName annotated fields. If you are on a version lower than 2.11, upgrade to Gson 2.11 first, because it has the necessary keep rules, and then delete the keep rules that target the classes used for Gson serialization and deserialization. If a class has no no-args constructor, keep a narrow rule for it.

Case: Retrofit

Retrofit has shipped with its own consumer keep rules from 2.10.0 and higher (2.9.0 already covers the @GET/@POST interface rule), so any keep rules for the library or classes depending on Retrofit are detrimental to the optimization process.

Blanket library preservation

This is the most harmful Retrofit rule as it disables any shrinking for the entire library.

-keep class retrofit2.** { *; }
-keep class retrofit2.api.** { *; }
-keep class com.package.example.retrofit.api.** { *; }
Manual annotation keeps

Retrofit's consumer rules automatically keep the interfaces annotated with @GET, @POST, @DELETE, @PUT, @HEAD, @OPTIONS, and @PATCH, making these manual rules obsolete.

-keepclasseswithmembers class * { @retrofit2.http.* <methods>; }
Redundant network response and adapter rules

Network responses and third-party adapter wrappers (like RxJava) are often overly preserved by developers out of caution.

-keep,allowobfuscation,allowshrinking class retrofit2.Response
-keep,allowobfuscation,allowshrinking class kotlin.coroutines.Continuation
-keep class retrofit2.adapter.rxjava2.Result { *; }

The fix : Verify you are using Retrofit 2.10.0 and higher. Retrofit from 2.9.0 bundles rules that detect its own HTTP annotations (@GET, @POST) (View Retrofit's embedded ProGuard rules), and from 2.10.0 it also keeps retrofit2.Response and kotlin.coroutines.Continuation. It automatically keeps the method signatures it needs to work.

Case: Kotlin coroutines

Kotlin Coroutines comes heavily optimized out of the box with embedded R8 rules (kotlinx-coroutines-core and kotlinx-coroutines-android include their own rules).

Blanket coroutine library rules

Keeping everything under kotlinx.coroutines is extremely detrimental to app size, as coroutines contain a vast amount of internal APIs that aren't used.

-keepclassmembers class kotlinx.coroutines.** { *; }
Redundant internal continuations

These low-level coroutine elements are preserved safely by the library's own consumer rules. Manually adding these prevents R8 from performing internal optimizations (such as removing unused continuations or inlining).

-keepclassmembers class kotlin.coroutines.SafeContinuation { *; }
Dispatcher and exception handler rules

Sometimes developers notice crashes related to missing classes on older Android versions and add these rules, but if you are using an up-to-date version of Kotlin Coroutines, these are handled automatically or are not an issue. kotlinx-coroutines-core keeps MainDispatcherFactory and CoroutineExceptionHandler, and kotlinx-coroutines-android keeps AndroidExceptionPreHandler and AndroidDispatcherFactory.

-keepnames class kotlinx.coroutines.internal.MainDispatcherFactory {}
-keepnames class kotlinx.coroutines.CoroutineExceptionHandler {}
-keepnames class kotlinx.coroutines.android.AndroidExceptionPreHandler {}
-keepnames class kotlinx.coroutines.android.AndroidDispatcherFactory {}

The fix : Remove any broad kotlinx keep rules. Kotlin Coroutines (1.7.0 and higher ) bundles the necessary keep rules (View Coroutines' embedded ProGuard rules).

Case: Parcelable and enums

Common mistakes : Legacy projects often contain manual Parcelable or enum keep rules:

-keep class * implements android.os.Parcelable { public static final android.os.Parcelable$Creator *; }
-keepclassmembers enum * { *; }

The fix:

  1. The default ProGuard file proguard-android-optimize.txt already includes the necessary keep rules for all Parcelable CREATOR fields and enum methods (values and valueOf).

  2. Delete all manual Parcelable and enum rules: Delete these manual keep rules without proposing any replacement rules.

  3. (Optional for Parcelable) : Use the kotlin-parcelize plugin and @Parcelize annotation to avoid manual writeToParcel boilerplate.

  4. Ideal rule : None. Delete all manual Parcelable and enum keeps.

Case: Room database

Common mistakes : Keeping DAO interfaces or the generated _Impl classes manually.

-keep class * extends androidx.room.RoomDatabase
-keep class *_*Impl { *; }

The fix: Room generates its own ProGuard rules for the code it creates. Manual rules are redundant and prevent R8 from optimizing the database access layers.

  • Ideal rule : None. Delete all manual Room or DAO keeps.

Summary

If you have updated your libraries to the versions mentioned, your proguard-rules.pro must not contain any keep rules for the libraries mentioned here.

Requirements and compatibility

Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta

“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.

Needs: Needs Python

Security

What our scanner noticed· Low risk

  • Instructions that use the network
  • Scripts that your agent may run

This skill includes scripts that your agent may run. Read them before you use it.

A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.

Attribution and licence

Created by
Google LLC
Publisher
Android (Google) (Official)
Distributed by
Android (Google)
Source
android/skills · performance/r8-analyzer · commit bf68e2d
Licence
Apache License 2.0 (redistribution allowed)
  • LICENSE (added by AutoGineer from LICENSE.txt)
  • ATTRIBUTION.md (written by AutoGineer)
Synced

AutoGineer is not affiliated with or endorsed by Google LLC or Android (Google).

Download ZIP

The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download r8-analyzer.zip