From 4f7418b3ad48f8006e666006428eed6f98aca51d Mon Sep 17 00:00:00 2001 From: David Schachter Date: Thu, 29 Oct 2026 10:41:52 -0700 Subject: [PATCH 1/3] ADFA-6822: pin R8 8.13.25 so D8 can rewrite Kotlin 2.3 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: 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 Claude-Session: https://claude.ai/code/session_01Vh2DAYXNkCD7buZPP5ZbJP --- .github/workflows/debug.yml | 9 ++++++++- build.gradle.kts | 5 +++++ gradle/libs.versions.toml | 3 +++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/.github/workflows/debug.yml b/.github/workflows/debug.yml index e133a5e6d9..036011b96b 100644 --- a/.github/workflows/debug.yml +++ b/.github/workflows/debug.yml @@ -228,8 +228,15 @@ jobs: - name: Assemble Universal APK run: | echo "gradle_time_start=$(date +%s)" >> $GITHUB_ENV - flox activate -d flox/base -- ./gradlew :app:assembleV8Debug --no-daemon + set -o pipefail + flox activate -d flox/base -- ./gradlew :app:assembleV8Debug --no-daemon 2>&1 | tee "$RUNNER_TEMP/assemble.log" echo "gradle_time_end=$(date +%s)" >> $GITHUB_ENV + # D8 logs this (non-fatal) once per class when the pinned R8 is older than the Kotlin + # metadata version, burying every real diagnostic. See the `r8` pin in libs.versions.toml. + if grep -q "Unexpected error during rewriting of Kotlin metadata" "$RUNNER_TEMP/assemble.log"; then + echo "::error::D8 could not rewrite Kotlin metadata. The R8 pinned in gradle/libs.versions.toml is too old for the current Kotlin version; bump 'r8' (ADFA-6822)." + exit 1 + fi - name: Find APK file diff --git a/build.gradle.kts b/build.gradle.kts index 15a7836cc3..2865d438a6 100755 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -61,7 +61,12 @@ jacoco { } buildscript { + repositories { + google() + } dependencies { + // Must stay first: pins a D8/R8 that understands the Kotlin metadata version (ADFA-6822). + classpath(libs.android.r8) classpath(libs.kotlin.gradle.plugin) classpath(libs.nav.safe.args.gradle.plugin) } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 3ca884d690..a3262b8953 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -20,6 +20,7 @@ junit-jupiter = "5.10.2" anroidx-test-core = "2.2.0" koinAndroid = "4.1.1" kotlin = "2.3.0" +# A Kotlin minor bump may need a newer `r8` (below): AGP 8.8.2's bundled D8 cannot rewrite Kotlin 2.3 metadata (ADFA-6822). kotlin-coroutines = "1.9.0" kotlinxCoroutinesCore = "1.10.2" lifecycleViewmodelKtx = "2.7.0" @@ -37,6 +38,7 @@ ksp = "2.3.6" antlr4 = "4.13.1" androidx-work = "2.10.0" androidx-espresso = "3.5.1" +r8 = "8.13.25" retrofit = "2.11.0" markwon = "4.6.2" maven-publish-plugin = "0.27.0" @@ -324,6 +326,7 @@ tooling-slf4j = { module = "org.slf4j:slf4j-api", version = "2.0.17" } snakeyaml-engine = { module = "org.snakeyaml:snakeyaml-engine", version = "2.10" } # Classpaths +android-r8 = { module = "com.android.tools:r8", version.ref = "r8" } android-gradle-plugin = { module = "com.android.tools.build:gradle", version.ref = "agp" } kotlin-gradle-plugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" } nav-safe-args-gradle-plugin = { module = "androidx.navigation:navigation-safe-args-gradle-plugin", version.ref = "androidx-navigation" } From 93d3061f64aaad19f27405d8bef2c41efd469636 Mon Sep 17 00:00:00 2001 From: David Schachter Date: Thu, 29 Oct 2026 10:51:17 -0700 Subject: [PATCH 2/3] ADFA-6822: address review of the R8 pin * 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 Claude-Session: https://claude.ai/code/session_01Vh2DAYXNkCD7buZPP5ZbJP --- .github/workflows/debug.yml | 2 +- build.gradle.kts | 3 --- gradle/libs.versions.toml | 4 +++- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/.github/workflows/debug.yml b/.github/workflows/debug.yml index 036011b96b..a02b182238 100644 --- a/.github/workflows/debug.yml +++ b/.github/workflows/debug.yml @@ -234,7 +234,7 @@ jobs: # D8 logs this (non-fatal) once per class when the pinned R8 is older than the Kotlin # metadata version, burying every real diagnostic. See the `r8` pin in libs.versions.toml. if grep -q "Unexpected error during rewriting of Kotlin metadata" "$RUNNER_TEMP/assemble.log"; then - echo "::error::D8 could not rewrite Kotlin metadata. The R8 pinned in gradle/libs.versions.toml is too old for the current Kotlin version; bump 'r8' (ADFA-6822)." + echo "::error::D8 could not rewrite Kotlin metadata. Most likely the R8 pinned in gradle/libs.versions.toml is older than the Kotlin metadata version (bump 'r8'), or the pin no longer takes effect on the build classpath. See ADFA-6822." exit 1 fi diff --git a/build.gradle.kts b/build.gradle.kts index 2865d438a6..06e157dd22 100755 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -61,9 +61,6 @@ jacoco { } buildscript { - repositories { - google() - } dependencies { // Must stay first: pins a D8/R8 that understands the Kotlin metadata version (ADFA-6822). classpath(libs.android.r8) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index a3262b8953..52e9d45cbf 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -20,7 +20,7 @@ junit-jupiter = "5.10.2" anroidx-test-core = "2.2.0" koinAndroid = "4.1.1" kotlin = "2.3.0" -# A Kotlin minor bump may need a newer `r8` (below): AGP 8.8.2's bundled D8 cannot rewrite Kotlin 2.3 metadata (ADFA-6822). +# A Kotlin minor bump may need a newer `r8` (see its entry below, ADFA-6822). kotlin-coroutines = "1.9.0" kotlinxCoroutinesCore = "1.10.2" lifecycleViewmodelKtx = "2.7.0" @@ -38,6 +38,8 @@ ksp = "2.3.6" antlr4 = "4.13.1" androidx-work = "2.10.0" androidx-espresso = "3.5.1" +# Pinned ahead of AGP on the root buildscript classpath: AGP 8.8.2's bundled D8 8.8.34 cannot rewrite +# Kotlin 2.3 metadata. Bump with `kotlin`; remove once AGP is upgraded (ADFA-6837). r8 = "8.13.25" retrofit = "2.11.0" markwon = "4.6.2" From a9e9af75acc930ada0f848600c44db214a322bd8 Mon Sep 17 00:00:00 2001 From: David Schachter Date: Fri, 30 Oct 2026 18:45:40 -0700 Subject: [PATCH 3/3] ADFA-6822: put the r8 note above the kotlin version it is about The note sat below `kotlin`, directly above `kotlin-coroutines`, so it read as being about coroutines. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Vh2DAYjFcUx64N8PMRknzL --- gradle/libs.versions.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 52e9d45cbf..cdc27caaf2 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -19,8 +19,8 @@ gson = "2.10.1" junit-jupiter = "5.10.2" anroidx-test-core = "2.2.0" koinAndroid = "4.1.1" -kotlin = "2.3.0" # A Kotlin minor bump may need a newer `r8` (see its entry below, ADFA-6822). +kotlin = "2.3.0" kotlin-coroutines = "1.9.0" kotlinxCoroutinesCore = "1.10.2" lifecycleViewmodelKtx = "2.7.0"