Published November 29, 2026

Google Tells Android Library Authors to Ship Narrower Keep Rules, and Flutter Plugin Wrappers Are Next

Google Play recently added DEX code optimization thresholds for apps and games, and those thresholds turned an old argument about keep rules into a measurable score in the Play Console. Google followed the policy change with a guide for library authors on November 17, and the advice inside it lands directly on anyone who maintains a Flutter plugin with an Android implementation.

The reasoning is structural. R8 is Android's app optimizer: it removes unused code, optimizes what remains, and obfuscates the rest. It can only optimize inside the boundaries it is given, and one of those boundaries is the set of consumer keep rules bundled by the libraries an app depends on. When Play measures how much of an app survived optimization, it is measuring the app's own rules and every library's rules at the same time.

What a consumer keep rule actually does

A consumer keep rule is a rule embedded inside an Android or JAR library that tells R8 which parts of the library must not be optimized during app-level compilation. It differs from the rules a library writes for its own minification, because consumer rules are merged into the consuming app's build and change what the whole-app optimizer is allowed to touch.

The intent is reasonable. A library that reaches a class through reflection, or that hands a class name to native code over JNI, has no static reference R8 can follow. Without a keep rule the optimizer deletes the target and the app crashes at runtime. A package-wide rule that keeps every class in the package is the easy way to make that crash disappear, and for years it was the default answer.

The cost of that answer compounds. A broad rule preserves code the app never calls, which inflates download size, startup time, memory use, and ANR rates. Google's post is blunt about the second-order effect: performance-minded apps end up writing their own rules to override a library's broad ones, and once they have done that they are reluctant to take library updates, because each update risks undoing a hand-tuned build.

Where Flutter plugins fit

A Flutter plugin with a native Android side is an Android library with a Dart wrapper on top. Its android/build.gradle can point consumerProguardFiles at a consumer-rules.pro file, and if it vendors a third-party SDK, the rules it ships are usually inherited from that SDK's own packaging. From R8's perspective there is no difference between a plugin and any other AAR, which means the plugin is judged in the same Play Console metric as the app it is embedded in.

That creates an uncomfortable ownership gap. Plugin authors rarely see the apps that use them, and app developers rarely read the consumer rules bundled inside a dependency. Google's recommendation that library authors test with a sample app and inspect what the app developer will see is precisely the step that gap skips.

The recommended toolkit is concrete and mostly free:

  • Enable R8 in a sample app and run the critical user journeys, rather than relying on a debug build that never shrinks.
  • Run the R8 Configuration Analyzer on that sample app to see the same optimization, shrinking, and obfuscation percentages an app developer sees.
  • Use the analyze command from the Android CLI against the AAR or JAR to list kept methods, classes, and fields, and compare the numbers across releases to catch regressions.
  • Watch library version adoption and crashes in the Google Play SDK Console.

The techniques that replace a blanket keep

For reflection, the guidance is to keep entry points and nothing else. R8 starts from the entry points and follows the references, so naming one class or method is usually enough to protect the code behind it. Scoping at that level also works for libraries that already ship an optimized or obfuscated build, because the rules still apply during the app's compilation and R8 can squeeze further based on what the app actually uses.

The second technique is to avoid reflection where codegen will do. Generated code is visible to R8 at build time, so it needs almost no keep rules. Serialization and dependency injection are the canonical examples, and Hilt is the reference implementation Google cites. Reflection still has a place for optional dependencies, where a code path may not exist at all, and in that case narrow rules around the optional entry point are the right shape.

Jetpack Keep annotations, now in alpha, aim at the maintenance problem behind all of this. Annotating a reflection site lets the build generate the keep rule instead of a human writing it by hand and forgetting to update it when the code moves.

Two narrower cases are worth memorizing. A rule like keeping every public class in a large third-party package subsumes the carefully written narrow rules that the downstream library already ships, so an app ends up with more code than either library intended. And an ad mediation adapter should use conditional keep rules that only preserve a format when the matching adapter is present in the app, rather than keeping every format for every consumer.

For a Flutter plugin maintainer the first move is small: open the consumer rules the plugin ships, count the package-wide patterns, and ask which of them could be replaced by an entry point. The second move is to add an example app to the CI matrix with R8 on, because that is the only place these rules are actually exercised. Play has made optimization a public number. The dependencies that quietly drag it down are the ones nobody is looking at.