chore: enable R8 optimised resource shrinking and guard it - #183
Open
code418 wants to merge 2 commits into
Open
Conversation
Investigation finding: R8 code + resource shrinking is already enabled by Flutter's Gradle plugin default. Spec covers the remaining cleanup and opt-ins: drop the dead android.enableR8 flag, add android.r8.optimizedShrinking, and assert release stays R8-optimised so the implicit default can't silently regress. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Android Studio prompted to "enable app optimization with R8". R8 code +
resource shrinking is already on (Flutter's Gradle plugin enables it for
release by default), so this covers the remaining gaps rather than a first
enablement:
- drop android.enableR8=true — AGP has had it Enforced since 7.0 and warns
to delete it; it misleads readers about where the real switch lives
- add android.r8.optimizedShrinking=true — AGP 8.11's name for R8 optimised
resource shrinking; prerequisites already default on
- assert release stays minifyEnabled + shrinkResources so the implicit
Flutter default can't silently regress via -Pshrink=false or an upstream
change
Verified: phone/wear/auto release builds all shrink (-719K/-670K/-478K B),
-Pshrink=false now fails fast with the assertion, and the phone release APK
renders cleanly on the Pixel 7a emulator (no missing shrunk resources).
The IDE quick-fix inserts the AGP 9.3+ optimization{enable=true} DSL, which
does not exist on our AGP 8.11.1 and fails to configure; this uses the
correct 8.11 path.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
android.enableR8=trueflag fromgradle.properties(AGP has had itEnforcedsince 7.0 and warns to delete it).android.r8.optimizedShrinking=true— AGP 8.11's name for R8 optimised resource shrinking (prerequisitesintegratedResourceShrinking+nonFinalResIdsalready default true).app/build.gradlethat thereleasebuild type staysminifyEnabled+shrinkResources, so the implicit Flutter default can't silently regress.Why
Android Studio surfaced a prompt to "Enable app optimization with R8". Investigation showed R8 code + resource shrinking is already on — the Flutter Gradle plugin enables it for
releaseby default (minify{Phone,Auto,Wear}ReleaseWithR8all run;mapping.txtshows R8 8.11.18 with 450k renamed symbols; full mode + integrated resource shrinking both default on). So the real gaps were: an obsolete no-op flag that misleads readers about where the switch lives, the one remaining opt-in the docs call out, and nothing in-repo pinning the behaviour.The IDE quick-fix for that prompt inserts the AGP 9.3+
optimization { enable = true }DSL, which does not exist on our AGP 8.11.1 (Optimizationhas noenableproperty until 9.3) and fails at configuration time — this PR uses the correct 8.11 path instead.Design spec:
docs/superpowers/specs/2026-07-24-r8-app-optimization-design.md.Note: R8 only optimises the Java/Kotlin layer; the Dart code in
libapp.sois untouched (--obfuscateis a separate, out-of-scope lever).Test plan
flutter build appbundle --flavor phone --releasebuilds clean (assertion passes, R8 runs)flutter build appbundle --flavor wear --release -t lib/main_wear.dartbuilds cleanflutter build apk --flavor auto --release -t lib/main.dartbuilds cleanphonerelease APK on emulator: launch, login, Nearby map, James strip, claim quiz, History, About all render (no missing shrunk resources)-Pshrink=falsenow fails with the R8-optimised assertion (guard works)