Skip to content

chore: enable R8 optimised resource shrinking and guard it - #183

Open
code418 wants to merge 2 commits into
masterfrom
chore/enable-r8-app-optimization
Open

chore: enable R8 optimised resource shrinking and guard it#183
code418 wants to merge 2 commits into
masterfrom
chore/enable-r8-app-optimization

Conversation

@code418

@code418 code418 commented Jul 27, 2026

Copy link
Copy Markdown
Owner

Summary

  • Remove the dead android.enableR8=true flag from gradle.properties (AGP has had it Enforced since 7.0 and warns to delete it).
  • Enable android.r8.optimizedShrinking=true — AGP 8.11's name for R8 optimised resource shrinking (prerequisites integratedResourceShrinking + nonFinalResIds already default true).
  • Assert in app/build.gradle that the release build type stays minifyEnabled + 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 release by default (minify{Phone,Auto,Wear}ReleaseWithR8 all run; mapping.txt shows 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 (Optimization has no enable property 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.so is untouched (--obfuscate is a separate, out-of-scope lever).

Test plan

  • flutter build appbundle --flavor phone --release builds clean (assertion passes, R8 runs)
  • flutter build appbundle --flavor wear --release -t lib/main_wear.dart builds clean
  • flutter build apk --flavor auto --release -t lib/main.dart builds clean
  • Release AAB/APK sizes hold or shrink vs baseline (no regression from optimised shrinking)
  • phone release APK on emulator: launch, login, Nearby map, James strip, claim quiz, History, About all render (no missing shrunk resources)
  • Sanity: a build with -Pshrink=false now fails with the R8-optimised assertion (guard works)

code418 and others added 2 commits July 27, 2026 09:43
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant