Repository navigation
Add R8 regression check workflow - #219
Merged
Merged
Conversation
…GP 9.2.1 baseline
cwoodwar6
reviewed
Oct 28, 2026
- check_library_shrinking.py: read the keys `android analyze` actually outputs (keptItemCount, configuration.used/unusedPackageWideKeepRules, blockedKeepRules[].source) and count rules with len(). Package-wide consumer rules were always reported as 0 before (watchface has 11). Drop the redundant keep ratio and rename format_kb to format_size. - check_app_r8_score.py: single default AAB path, drop --build and the old JSON shape, read the package name from --analysis=basic. - Remove ANDROID_CLI_ANALYZE (no longer needed) and --no-configuration-cache from the scripts and workflow. - Always run the git hooks, the pre-commit config hooks and the CI workflow instead of filtering by changed files. - Post one PR comment and edit it on later runs. - Remove check_r8_regression.py, superseded by the split scripts.
🛡️ R8 Optimization & Shrinking Gate (
|
| Metric | Baseline | Current | Delta | Threshold | Status |
|---|---|---|---|---|---|
| Shrinking Score | 52.49% | 51.64% | -0.85% pts |
max -2.00% pts |
✅ PASS |
| Optimization Score | 52.15% | 51.30% | -0.85% pts |
max -2.00% pts |
✅ PASS |
| Obfuscation Score | 52.45% | 51.61% | -0.84% pts |
max -2.00% pts |
✅ PASS |
| Uncompressed DEX Size | 17.99 MB | 17.53 MB | -0.45 MB (-2.5%) |
max +5.0% / +500KB |
✅ PASS |
📚 Library Shrinking Percentage (Min Threshold: 90.0%)
- Libraries Analyzed: 12 (✅ 11 passed,
⚠️ 1 with package-wide keep rules, ❌ 0 failed)
On every PR, post a GitHub-style diff of the keep rules that changed compared with main, and the classes they keep. It covers rules that come with library upgrades and existing wildcard rules that start keeping new classes, neither of which shows up in the PR's own diff. It doesn't build anything. With AGP 9.3.2, every release build writes the keep rule .pb file (app/build/outputs/mapping/release/configanalyzer.pb) by default, so the gate uploads the file from the build it already runs. - keep_rule_diff.yml: reusable workflow, given the .pb file's path. On pushes to main it caches the file per commit; on PRs it diffs against main's cached file, writes the job summary and keeps one PR comment up to date. - r8_regression_check.yml: upload the .pb file after the release build and call keep_rule_diff.yml in a second job, which also runs when the gate fails. Optionally skip the diff when the R8 scores didn't change (KEEP_RULE_DIFF_ONLY_IF_SCORES_CHANGED). - scripts/keep_rule_diff.py and scripts/schema_pb2.py: compare two keep rule .pb files and write the Markdown report. Needs AGP 9.3 or newer to write the .pb file; until then the diff is skipped.
zizmor's excessive-permissions audit flags workflow-level write permissions once a workflow has more than one job, which the new keep-rule-diff job made it. Move them to the r8-regression-gate job; keep-rule-diff already sets its own (contents: read, pull-requests: write).
main doesn't run the keep rule diff yet, so the cache has no keep rules from main to compare this PR against. A temporary job builds the PR's base commit once, with AGP 9.3.2 so that it writes the keep rule .pb file, and caches it under the key the keep-rule-diff job looks for. To be removed once the diff has run.
cwoodwar6
approved these changes
Oct 29, 2026
cwoodwar6
left a comment
There was a problem hiding this comment.
I'm not sure if having the keep rule diff is worth the added proto complexity. It is nice to have when a library changes a keep rule, but for anything changed within the project, those changes are already visible in the git diff.
Drop the keep rule diff and the temporary job that seeded main's keep rules for it. The R8 regression gate itself is unchanged. - keep_rule_diff.yml, scripts/keep_rule_diff.py and scripts/schema_pb2.py: deleted. - r8_regression_check.yml: remove the keep-rule-diff and seed-keep-rule-base jobs, the upload of the keep rule .pb file, and the optional check of whether the R8 scores changed (KEEP_RULE_DIFF_ONLY_IF_SCORES_CHANGED).
Android CLI 1.1.16919734 writes the AAR and JAR DEX sizes as JSON strings, because they're now int64 values. The library check already reads them with int(), so add a comment to keep it that way. An outdated CLI prints an update notice on stdout after the JSON, which made json.loads fail with "Extra data". Parse only the JSON object. Regenerate r8-baseline.json with the latest CLI from the AGP 9.3.2 release build. The old baseline came from an older CLI and an AGP 9.2.1 build.
Drop the Gemini CLI step and the r8-analyzer skill install, along with the build file diff and the .gitignore edit that only the review used. The scorecard now goes to the runner's temporary folder instead of .gemini/, and the pull request comment contains only the scorecard.
List only the libraries that regressed instead of a row for every library, to keep the PR comment short. The job log still prints every library.
The table already marks the failing app metrics, so stop repeating them as a list below it. Failures without a table row, such as R8 full mode being turned off, are still listed. Also drop the lowest library shrinking line, which repeated the worst library's regression.
cwoodwar6
approved these changes
Nov 24, 2026
| "package_name": result.get("basic", {}).get("appInfo", {}).get("packageName", "N/A"), | ||
| "agp_version": bundle.get("agpVersion", "N/A"), | ||
| "r8_version": r8_json.get("version", "N/A"), | ||
| "r8_enabled": marker.get("r8Enabled", False), |
There was a problem hiding this comment.
R8 enablement is implied by the presence of r8Json (version is a decent proxy). I might write this as "r8_enabled": r8_version != "N/A" or marker.get("r8Enabled", False),
R8 enablement is implied by the presence of r8.json, and its options say whether full mode is on. Fall back to the DEX marker only when r8.json lacks them.
Drop the pre-commit and pre-push hooks, their pre-commit config, and the staged diff check that only the hooks ran. The GitHub Actions workflow is the gate.
raystatic
approved these changes
Nov 25, 2026
srikrishnasakunia
approved these changes
Nov 25, 2026
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.
Adds CI (GitHub Actions) regression gates powered by
android analyzeto catch R8 configuration regressions, unshrunk libraries, and DEX size bloat before merge.1. Prerequisites & Setup Requirements
To adopt this workflow in a repository, the following baseline file, secrets, build settings, and tools are required:
A. Initial R8 Baseline File (
r8-baseline.json)check_app_r8_score.pycompares every PR's release App Bundle (.aab) against a committedr8-baseline.jsonfile in the repository root. This file stores the referenceandroid analyzeoutput (shrinkingRatio,optimizationRatio,obfuscationRatio, anduncompressedDexSizeBytes).r8-baseline.jsonwhenever a passing PR merges tomain.B. GitHub Actions Secrets & Permissions
Configure the following in Settings → Secrets and variables → Actions:
GITHUB_TOKEN/ OptionalPAT):contents: write,pull-requests: write, andissues: writepermissions so it can post scorecard comments on PRs (gh pr comment) and auto-commit updatedr8-baseline.jsonfiles onmain.PATSecret: If yourmainbranch has branch protection rules that blockgithub.tokenfrom pushing commits, add a Personal Access Token secret namedPATwithrepo/contents: writescope.DEBUG_GOOGLE_SERVICES_JSON_BASE64)::app:bundleReleasein CI (in Androidify, ifDEBUG_GOOGLE_SERVICES_JSON_BASE64is not set, the workflow falls back to copyingtest-google-services.jsontoapp/google-services.json).C. Android Gradle Plugin (AGP) & R8 Build Configuration
isMinifyEnabled = true):app/build.gradle.kts, thereleasebuild type must haveisMinifyEnabled = true.BUNDLE-METADATA/com.android.tools/r8.jsoninsideapp-release.aab, whichandroid analyzereads to calculate shrinking, optimization, and obfuscation scores.consumerProguardFiles):check_library_shrinking.py --scan-libraries), library modules must build release AARs (./gradlew assembleRelease) soandroid analyzecan inspect their packagedproguard.txtconsumer rules and run isolated D8 vs. R8 shrinking comparisons.D. Android CLI
android):https://dl.google.com/android/cli/latest/linux_x86_64/install.sh(or locally on macOS viadarwin_arm64/install.sh), providing theandroid analyze --analysis=optimizationcommand.2. Modular Check Scripts (
scripts/)Teams can adopt both checks or pick only the one that fits their workflow:
check_library_shrinking.py.aar&.jarmodules/libraries(1 - r8DexSize / d8DexSize) * 100) and flags consumerproguard.txtrules with package-wide wildcardscheck_app_r8_score.py.aab)shrinkingRatio,optimizationRatio,obfuscationRatio(0–100) anduncompressedDexSizeBytesagainstr8-baseline.json3. GitHub Actions Workflow (
.github/workflows/r8_regression_check.yml)Triggers & Inputs
pull_request/push(main): Runs automatically whenever ProGuard/R8 files (**/*.pro), Gradle build scripts (**/build.gradle.kts,gradle/libs.versions.toml,gradle.properties),r8-baseline.json, orscripts/check_*.pychange.workflow_dispatch: Supports manual execution against any PR or commit with configurable thresholds:pr_number: Optional PR number to checkout and comment on.max_score_drop(default2.0): Maximum allowed drop in R8 shrinking, optimization, or obfuscation scores (percentage points).max_dex_growth_pct(default5.0): Maximum allowed uncompressed DEX size increase (%).min_lib_shrinking_pct(default90.0): Minimum required isolated DEX shrinking percentage for module AARs (%).Workflow Pipeline Steps
androidCLI (https://dl.google.com/android/cli/latest/linux_x86_64/install.sh)../gradlew :app:bundleRelease assembleReleaseto produce the release App Bundle (app-release.aab) and module AARs (*-release.aar).app_r8_gate): Runscheck_app_r8_score.pyto compare the release.aabagainstr8-baseline.jsonand writes the scorecard to$RUNNER_TEMP/r8_summary.mdand$GITHUB_STEP_SUMMARY.lib_r8_gate): Runscheck_library_shrinking.py(--scan-libraries --append-summary) across built module AARs to verify isolated R8 shrinking ratios and flag package-wide consumer keep rules.main: Onpushtomainwhen both gates pass, runscheck_app_r8_score.py --save-baselineand auto-commits updated metrics tor8-baseline.json.gh pr comment, uploadsr8-config-analyzer-report(r8-config-analyzer-release.html), and fails the check if any regression threshold was breached.