r8-shrink-pro
Skill8 starsChanged 13 days agoMITView on GitHub
Reviews Android R8 / ProGuard configuration for code-shrinking, optimization, and obfuscation. Covers `-keep` rule discipline, library `consumer-rules.pro` discipline, common reflection-using library rules (Moshi, Room, Hilt, Retrofit, Glide), mapping-file workflow, debugging release-build crashes. Use when reading, writing, or reviewing ProGuard/R8 configuration files.
In this repository40 other files it gives its agents.
- AGENTS.mdAGENTS.md
- docs/agents.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- android-accessibility-proSkill
- android-adaptive-layout-proSkill
- android-compose-proSkill
- android-coroutines-proSkill
- android-design-system-proSkill
- android-gradle-architecture-proSkill
- android-library-proSkill
- android-memory-storage-proSkill
- android-modularization-proSkill
- app-intents-proSkill
- beta-deployment-proSkill
- coredata-swift6-proSkill
- cross-platform-parity-proSkill
- flaky-tests-proSkill
- foundation-models-proSkill
- instruments-profiling-proSkill
- linting-proSkill
- localization-proSkill
- motion-design-proSkill
- store-compliance-proSkill
- swift-accessibility-proSkill
- swift-adaptive-layout-proSkill
- swift-concurrency-proSkill
- swiftdata-proSkill
- swift-design-system-proSkill
- swift-docc-proSkill
- swift-error-handling-proSkill
- swift-library-proSkill
- swift-logging-proSkill
- swift-memory-storage-proSkill
- swift-modularization-proSkill
- swift-package-proSkill
- swift-testing-proSkill
- swiftui-proSkill
- visionos-proSkill
- xcode-security-proSkill
- xml-to-compose-migration-proSkill
The file
We split this skill into the rules it gives an agent
3 rules. About 0 are common, 1 is distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 18
Check common reflection-library rules using references/library-keep-rules.md — Moshi, Room, Retrofit, Hilt, Glide, kotlinx-serialization.
- Distinctive: line 22
If doing a partial review, load only the relevant reference files.
- Very specific: line 24
Official companion: when Google's Android skills (android/skills, Apache-2.0) are installed, see r8-analyzer, which inspects the merged R8 …
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Review Android R8 / ProGuard configuration for correctness, minimal-keep discipline, and release-build resilience. R8 is the default code shrinker in AGP 8.x — it's ProGuard-compatible (same -keep rule syntax) but with better optimization and bundled obfuscation. Report only genuine problems; don't add -keep rules speculatively.
Review process:
- Frame what R8 is doing using
references/fundamentals.md— shrinking, optimizing, obfuscating, repackaging; whatminifyEnabled = trueactually triggers. - Validate
-keeprule discipline usingreferences/keep-rules.md— when to use-keepvs-keepclassmembersvs-keepnames, and why blanket-keepis wrong. - For library modules, check
consumer-rules.prousingreferences/consumer-rules.md— what libraries owe their consumers. - Check common reflection-library rules using
references/library-keep-rules.md— Moshi, Room, Retrofit, Hilt, Glide, kotlinx-serialization. - Validate mapping-file workflow using
references/mapping-files.md— keepingmapping.txt, deobfuscating stack traces, Crashlytics integration. - Diagnose release-build crashes using
references/common-crashes.md—ClassNotFoundException,NoSuchMethodException, native-library symbol mismatches.
If doing a partial review, load only the relevant reference files.
Official companion: when Google's Android skills (android/skills, Apache-2.0) are installed, see r8-analyzer, which inspects the merged R8 configuration of a real build. Use it for evidence; use this skill for keep-rule discipline and crash triage.
Core Instructions
- R8 is default in AGP 3.4+. The
proguardFilesdirective uses ProGuard rule syntax; R8 interprets them. There's no separate "use R8" flag —minifyEnabled = trueturns it on. - Default to
proguard-android-optimize.txt+ yourproguard-rules.pro. AGP ships sensible defaults viagetDefaultProguardFile("proguard-android-optimize.txt"). - Library modules use
consumer-rules.pro, notproguardFiles. Rules inconsumer-rules.proare inherited by every consumer that depends on the library. Seeconsumer-rules.md. -keepis the heavy hammer — it prevents shrinking, optimization, AND obfuscation for the matched class. Prefer narrower forms (-keepclassmembers,-keepnames) when only one of those is needed.- Reflection-using libraries (Moshi, Room, Retrofit, Hilt, Glide, kotlinx-serialization) need keep rules. Most ship their own
consumer-rules.pro, but some (or custom uses) require app-level additions. - Always test release builds with
minifyEnabled = truebefore shipping. Many R8 crashes only surface in release. - Keep the
mapping.txtfrom every release. Without it, post-release crash reports are unreadable obfuscated stack traces.
Output Format
For ProGuard/R8 reviews, organize findings by file. For each:
- State the file (
proguard-rules.pro,consumer-rules.pro, etc.) and line. - Name the rule issue.
- Show before/after.
Skip files with no issues. End with a prioritized summary.
Example output:
proguard-rules.pro
Line 8: -keep class com.kozinga.** { *; } is too broad — defeats shrinking for the entire app code.
# Before
-keep class com.kozinga.** { *; }
# After — keep only what reflection actually touches:
-keep @com.squareup.moshi.JsonClass class * { <fields>; }
-keepclassmembers class com.kozinga.models.** {
@com.squareup.moshi.Json *;
}Line 18: -keepnames on a class that's reflectively constructed — should be -keep.
# Before — preserves the name but allows R8 to remove the class:
-keepnames class com.kozinga.WebViewBridge
# After — preserves the class itself:
-keep class com.kozinga.WebViewBridge { *; }consumer-rules.pro (missing for :core:network)
Library :core:network exposes Retrofit interfaces but doesn't ship consumer-rules.pro — consumers' R8 strips method signatures that Retrofit needs at runtime.
# consumer-rules.pro for :core:network
-keep,allowobfuscation,allowshrinking interface retrofit2.Call
-keep,allowobfuscation,allowshrinking class kotlin.coroutines.Continuation
-keepattributes Signature, InnerClasses, EnclosingMethodSummary
- Over-broad keep (high):
com.kozinga.**blanket keep defeats shrinking for the entire app. - Missing consumer-rules.pro (high): Library
:core:networkdoesn't ship Retrofit-required rules. - Wrong keep variant (low):
-keepnameswhere-keepis needed.
End of example.
References
references/fundamentals.md— what R8 does (shrink / optimize / obfuscate / repackage), how it differs from old ProGuard, full-mode vs compatibility-mode, whatminifyEnabledtriggers,shrinkResourcesfor resources.references/keep-rules.md—-keep,-keepclassmembers,-keepclasseswithmembers,-keepnames,-keepattributes. Class-spec syntax (@Annotation class * { <fields>; }). The hierarchy from most-specific to least-specific.references/consumer-rules.md—consumer-rules.procontract with library consumers. When to use it vs in-treeproguard-rules.pro. Library authors' responsibility for shipping correct rules.references/library-keep-rules.md— concrete rules for Moshi (@JsonClass), Room (@Entity/@Dao), Retrofit (annotation-driven methods), Hilt (generated classes), Glide (modules), kotlinx-serialization (annotated classes), reflection-via-Class.forName.references/mapping-files.md—mapping.txtretention, deobfuscating release stack traces (retrace), Crashlytics mapping upload, R8 missing-rules report (-printusage,-printseeds,-printmapping).references/common-crashes.md—ClassNotFoundException,NoSuchMethodException,InvocationTargetExceptionfrom missing reflection rules, native-library symbol mismatches (UnsatisfiedLinkError), Kotlin metadata stripping (KotlinClassNotFoundException).
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

