跪拜 Guibai
← All articles
Frontend · Android · Flutter

Google's 2027 DEX Optimization Bar Turns Whole-Package `-keep` Rules into a Release Blocker

By 恋猫de小郭 ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

From February 2027, apps with large DEX files that don't hit 25% shrinking, optimization, and obfuscation will lose Google Play visibility and may be blocked from publishing; SDK authors with broad `-keep` rules are therefore handing every downstream app a compliance problem.

Summary

Starting February 2027, Google Play will require apps with uncompressed DEX of at least 10MB in the AAB (50MB for games) to shrink, optimize, and obfuscate at least 25% of code items each. Play Console already shows the metrics; missing the bar affects visibility and publishing.

The biggest obstacle is the common SDK practice of adding a blanket `-keep class com.example.** { *; }` to consumer rules to protect reflection and JNI call sites. Those rules get merged into every downstream app's R8 configuration, and a single package-level keep can freeze tens of thousands of code items, blocking shrinking, optimization, and obfuscation. The effect can even override finer rules from other SDKs, like a library keeping all of `com.google.android.gms.**`.

R8 Configuration Analyzer shows which rules retain which classes, fields, and methods, and flags subsumed rules. The command chain goes from `android analyze app-release.aab` for the final DEX and optimization ratios, to `android analyze --analysis=optimization -f json library.aar` for an AAR's own rules, to `./gradlew :app:analyzeReleaseR8Config` on AGP 9.3+ to generate a keep-rule impact report without a full build.

Takeaways
— Google Play's new thresholds, effective February 2027, target apps with uncompressed DEX >=10MB in the AAB and games with >=50MB; both must achieve at least 25% shrinking, optimization, and obfuscation.
— A single package-level `-keep` rule in an SDK's consumerProguardFiles gets merged into downstream app R8 configs and freezes all code items under that package.
— In a sample, one `-keep class org.bouncycastle.** { *; }` retained 55,268 code items, about 18% of the sample.
— A broad rule can override finer rules from another SDK, e.g., a library keeping `com.google.android.gms.**` overrides GMS's own fine-grained rules.
— R8 Configuration Analyzer identifies subsumed rules, meaning a finer rule for `org.apache.xerces.**` is useless if a broader `org.apache.**` rule exists; you must fix the broader rule.
— To audit: `android analyze app-release.aab` shows DEX size and optimization ratios; `android analyze --analysis=optimization -f json library.aar` inspects an AAR's rules; `./gradlew :app:analyzeReleaseR8Config` (AGP 9.3+) generates a keep-rule impact report without a full build.
Conclusions

The habit of adding a whole-package `-keep` rule is a default reflex for SDK authors, but the new Play thresholds turn that convenience into a cross-SDK liability, because the rule's impact is only visible in the downstream app's build.

Google is effectively nudging the ecosystem toward R8 Full mode and precise keep rules; the analyzer and CLI tools make it possible to audit, but the burden falls on SDK maintainers to change their consumer rules.

The subsumed-rule detection is the subtle part: even if you refine your own rule, a broader rule from another dependency can silently nullify it, so fixing the problem requires identifying the source AAR or app config.

Concepts & terms
consumerProguardFiles
A Gradle property in an SDK module that points to ProGuard/R8 rules files; the rules are packaged into the AAR and merged into downstream apps' R8 configurations.
R8 Configuration Analyzer
A tool that shows a keep-rule report, including how many classes, fields, and methods each rule retains and whether rules are subsumed.
Subsumed rules
R8 rules that are overridden by a broader rule; the narrower rule becomes ineffective because the broader one covers the same code items.
R8 Full
A mode of R8 where shrinking, optimization, and obfuscation are all enabled, as opposed to a lighter configuration. The article implies using R8 Full to meet the new Play thresholds.
Source: juejin.cn ↗ Google Translate ↗ Backup ↗