name: r8-assistant description: Narrows R8 and ProGuard keep rules and fixes release-only reflection crashes in Android apps, using runtime evidence from an instrumented debug build and verifying every change on a real R8 release build. Use this skill when asked to narrow, improve or shrink keep rules, reduce APK or DEX size, remove broad -keep rules or -dontobfuscate, or fix crashes that only happen in the release build, such as ClassNotFoundException, NoSuchMethodException, NoSuchFieldException or Fragment InstantiationException, or Gson, Moshi or kotlinx.serialization data that is missing in release. Don't use for static review of keep rule files without running the app (suggest the r8-analyzer skill), for keep rules that ship inside third-party libraries, for dynamic feature modules or JVM jars, or for crashes that also happen in debug builds. keywords:
This skill aligns the keep rules of an Android app with its runtime reflection. It logs reflection in an instrumented debug build, turns the log into keep rules, and checks each change on a real R8 release build.
It handles two tasks:
For a static review of keep rule files without running the app, suggest the r8-analyzer skill. When r8-analyzer marks a rule for refinement and runtime evidence is needed, continue here.
The skill runs version {{R8_ASSISTANT_VERSION}} of the R8 assistant command line tool. Every command reads the path of the jar from the R8_ASSISTANT_JAR environment variable.
The skill works on:
Leave keep rules from third-party dependencies unchanged. Name the dependency in the report when one of its rules is broad.
For the following cases, tell the user why the skill does not apply and stop:
isMinifyEnabled is false.-dontobfuscate, -dontshrink, -dontoptimize, or rules with package-wide wildcards such as com.example.**. They hide the cause and give up R8 savings for code that does not need them.androidx. or kotlin. library. See the limits in references/capture.md.build/r8-assistant/ in the app module, for example app/build/r8-assistant/. Delete the log on the device after each pull, and send no data off the machine.Stop, ask, and wait for the answer when:
ANDROID_SERIAL is not set.Follow references/setup.md to download and verify the jar, check the tools and the device, and find the app module, variant, rule files and application IDs. Run every command from the project root.
suggest on the log, and run query for the classes in the retraced stack trace, as described in references/rules.md.diff with all logs and all rule files that the project owns, as described in references/rules.md.Run the release replay after every rule change, as described in references/release-verification.md: build the release APK with R8, install it without instrumentation, replay each flow or release-compatible test, and check expectations, logcat and the retraced stack traces. Pass only with zero failures.
Use the templates in references/report.md. Include the evidence for each rule, the tests and journeys with their coverage, the result of the release replay, and for narrowing the DEX size before and after. Name the APK installed on the device at the end.
instrument adds reflection logging to an APK that is debuggable or signed with the debug key.suggest writes keep rules for the reflection in one or more logs.diff compares logs with existing rules and classifies each rule.query filters log events by class, member or event type.Every command prints its usage with --help. Check the usage before you use an option that this skill does not show:
java -jar "$R8_ASSISTANT_JAR" --help java -jar "$R8_ASSISTANT_JAR" diff --help
For options, outputs and exit codes, see references/cli.md. For errors, see references/troubleshooting.md.
./gradlew installDebug, or running connectedAndroidTest, after instrumenting. Both replace the instrumented APK, and connectedAndroidTest also uninstalls the app, which deletes its data.-keep class com.example.** { *; } or -dontobfuscate to make a crash go away../gradlew clean during a run. It deletes build/r8-assistant/.