Skip to content

ADFA-6822: pin R8 8.13.25 so D8 can rewrite Kotlin 2.3 metadata - #2209

Merged
davidschachterADFA merged 5 commits into
stagefrom
fix/ADFA-6822-d8-kotlin-metadata
Nov 4, 2026
Merged

davidschachterADFA merged 5 commits into
stagefrom
fix/ADFA-6822-d8-kotlin-metadata

Conversation

@davidschachterADFA

@davidschachterADFA davidschachterADFA commented Oct 29, 2026 •

Copy link
Copy Markdown
Collaborator

ADFA-6822: D8 "Unexpected error during rewriting of Kotlin metadata"

AGP 8.8.2 bundles D8 8.8.34, which predates Kotlin 2.3 metadata (mv=[2,3,0]) and throws Should never be called while rewriting it. D8 logged this once per class, burying every real diagnostic in the CI log.

This PR puts com.android.tools:r8:8.13.25 first on the root buildscript classpath so it wins over the R8 shaded in AGP's builder jar, and adds a CI guard so a Kotlin bump can't silently bring the problem back. Dropping the pin needs an AGP upgrade, tracked separately.

Changes

  • gradle/libs.versions.toml: r8 = "8.13.25" and android-r8, plus a comment next to kotlin that a Kotlin minor bump may need a newer r8.
  • build.gradle.kts: classpath(libs.android.r8) first in the root buildscript. It resolves from the repositories the build already declares, so the buildscript has no repositories block of its own.
  • .github/workflows/debug.yml: the Assemble step now tees the Gradle output and fails with an ::error:: if it contains Unexpected error during rewriting of Kotlin metadata.

Results (local :app:clean :app:assembleV8Debug --no-build-cache)

Before After
D8 version in use (temporary probe) 8.8.34 8.13.25
"Unexpected error during rewriting of Kotlin metadata" 21,546 0
Build log ~2.3M lines ~2.5k lines
APK size 114,628,533 B 114,710,453 B (+0.07%)
Dex files 37 37
NoSuchMethodError / NoClassDefFoundError n/a 0

An earlier baseline run counted 25,416; the ticket's 2,743 came from the CI log and undercounts.

Verified

  • :app:assembleV8Release, assembleV8Profileable, assembleV7Debug, :app:testV8DebugUnitTest and spotlessCheck all pass (BUILD SUCCESSFUL in 14m 14s, 0 metadata warnings).
  • Pixel 6 Pro (Android 17, arm64): the app launches, opens a project, Quick Build and the normal build both produce an APK and reach the installer. No FATAL EXCEPTION in logcat.

Not verified

  • That D8 now keeps valid Kotlin metadata on a given class. dexdump doesn't show annotation values; the Lkotlin/Metadata; reference counts match before and after (207), and runtime impact was probably nil to begin with (kotlin-reflect is not on :app's runtime classpath).
  • Installing the built app and attaching the debugger (needs the Play Protect prompt approved by hand).

Notes

  • The CI guard changes how the Assemble step captures output (2>&1 | tee). ADFA-6818, which merges the Gradle invocations, will need to preserve it.
  • This pin affects only this project's build classpath. The IDE's bundled on-device toolchain (agp-tooling 9.3.1) is untouched.
  • Rollback: revert the classpath line and the catalog entry.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Vh2DAYXNkCD7buZPP5ZbJP

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review for a one-time review, or @claude review always to subscribe this PR to a review on every future push.

Tip: disable this comment in your organization's Code Review settings.

@coderabbitai

coderabbitai Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review.

Summary
  • Pin com.android.tools:r8:8.13.25 first on the root buildscript classpath to address reported D8 errors rewriting Kotlin 2.3 metadata.
  • Add a CI guard that fails the V8 debug assembly if its Gradle log contains Unexpected error during rewriting of Kotlin metadata. The workflow captures the output and preserves Gradle’s exit status.
  • The author reports successful local V8 and V7 builds, V8 unit tests, and spotlessCheck, with zero metadata warnings. The author also reports launching the app and building APKs on a Pixel 6 Pro running Android 17.
  • Risk: The author did not verify that valid Kotlin metadata remains intact on individual classes. Installing the built app and attaching the debugger were also not verified.
  • Maintenance note: The R8 pin applies to the project’s build classpath, not the IDE’s bundled on-device toolchain. The version catalog says to update the pin with Kotlin and remove it after an AGP upgrade.

The buildscript adds R8 version 8.13.25 before the Kotlin Gradle plugin. The debug workflow captures APK assembly output and fails if it detects the specified D8 Kotlin metadata rewriting error.

Changes: R8 metadata build handling

Layer / File(s) Summary
Register the R8 dependency
build.gradle.kts, gradle/libs.versions.toml
The version catalog defines R8 8.13.25 and its library alias. The buildscript adds R8 to the classpath before the Kotlin Gradle plugin.
Capture and check assembly output
.github/workflows/debug.yml
The debug workflow logs Gradle assembly output and fails if the log contains Unexpected error during rewriting of Kotlin metadata.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: daniel-adfa, itsaky-adfa

Merge Risk: Minimal · previous review a9e9a

No actionable merge-blocking issue is established; the change is mergeable after normal checks.

Pre-merge checks: Passed 5
Check name Status Explanation
Title check Passed The title names the main change: pinning R8 to 8.13.25 so D8 can rewrite Kotlin 2.3 metadata. The raw summary and objectives both describe the R8 classpath pin and the Kotlin metadata error, so the ti…
Description check Passed The description states the problem (D8 8.8.34 throws errors rewriting Kotlin 2.3 metadata), the fix (R8 8.13.25 placed first on the root buildscript classpath), and the CI guard in the Assemble step. …
Docstring Coverage Passed No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: pinning R8 to 8.13.25 so D8 can rewrite Kotlin 2.3 metadata. The raw summary and objectives both describe the R8 classpath pin and the Kotlin metadata error, so the title matches the changeset.

Full details: Description check

Explanation

The description states the problem (D8 8.8.34 throws errors rewriting Kotlin 2.3 metadata), the fix (R8 8.13.25 placed first on the root buildscript classpath), and the CI guard in the Assemble step. It also lists the changed files and verification results. This matches the changeset.

Full details: Docstring Coverage

Explanation

No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 0 functions across 1 files. (1 skipped: 1 unsupported.)

Finishing Touches
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Tip

🎯 Customize your risk assessments

Guide how CodeRabbit assesses merge risk and security architecture risk. Highlight sensitive changes and explain your security boundaries using Merge Risk Instructions and Security Risk Instructions in your review settings. Security architecture risk assessments require the Advanced plan or above.

✅ Automatic approvals, with your rules

Let CodeRabbit approve pull requests once required threads are resolved, pre-merge checks pass, and your risk limits are met. Enable Automatic approvals in review settings, with overrides for teams or file paths.

A rabbit checks the build log bright,
Then pins R8 in place just right.
Gradle’s output leaves a trace,
D8 errors meet a guarded gate.
The bunny hops beneath the moon,
And hopes the build completes quite soon.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Essentials
  • Run ID: 9facc998-3d76-41b2-b00e-793ea48e5242
Commits

Reviewing files that changed from the base of the PR and between 4cc5433 and a9e9af7.

Files selected for processing: 1
  • gradle/libs.versions.toml
Files skipped from review as they are similar to previous changes: 1
  • gradle/libs.versions.toml

Included review availability: This review used your included allowance. 4 included reviews remain after this review. Your included PR review attempts over the past 7 days set your current allowance at 5 reviews per hour.

davidschachterADFA and others added 2 commits October 30, 2026 11:10
AGP 8.8.2 bundles D8 8.8.34, which predates Kotlin 2.3 metadata (mv 2.3.0)
and throws "Should never be called" while rewriting it. D8 logged this once
per class: 25,416 times, ~2.3M lines, in a local assembleV8Debug.

Put com.android.tools:r8 first on the root buildscript classpath so it wins
over the R8 shaded inside AGP's builder jar. A temporary probe confirmed the
version in use changed from 8.8.34 to 8.13.25.

Add a CI guard after the assemble step that fails if the warning reappears,
so a Kotlin bump cannot silently bring it back.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYXNkCD7buZPP5ZbJP
* Drop the root buildscript `repositories { google() }`: r8 resolves without
  it (checked with `buildEnvironment`), so it was a redundant third place to
  configure repositories.
* Move the rationale next to the `r8` catalog entry; leave a short pointer
  next to `kotlin`.
* Make the CI guard's error message not assume the pin is merely too old: the
  pin may also have stopped taking effect on the build classpath.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYXNkCD7buZPP5ZbJP
@davidschachterADFA
davidschachterADFA force-pushed the fix/ADFA-6822-d8-kotlin-metadata branch from e5d0b9f to 93d3061 Compare October 30, 2026 18:10
davidschachterADFA and others added 3 commits October 30, 2026 17:22
The note sat below `kotlin`, directly above `kotlin-coroutines`, so it read as being about
coroutines.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYjFcUx64N8PMRknzL
@davidschachterADFA
davidschachterADFA merged commit 9dffb7d into stage Nov 4, 2026
6 checks passed
@davidschachterADFA
davidschachterADFA deleted the fix/ADFA-6822-d8-kotlin-metadata branch November 4, 2026 16:59
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.

2 participants