Skip to content

build: Bump Kotlin to 2.4.21 and the language/API version to 2.1 - #6646

Draft
runningcode wants to merge 5 commits into
9.x.xfrom
no/kotlin-language-2.1
Draft

runningcode wants to merge 5 commits into
9.x.xfrom
no/kotlin-language-2.1

Conversation

@runningcode

@runningcode runningcode commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

📜 Description

Raises the Kotlin language/API version of every published module from 1.9 to 2.1, and compiles with Kotlin 2.4.21.

Breaking for 9.0: apps that compile Kotlin need Kotlin 2.0 or newer, up from 1.8. Apps written only in Java are not affected. This is the same minimum that stable AndroidX and Firebase already require.

  • Language/API version: the io.sentry.jdk-target convention now sets 2.1 for the main Kotlin compilations of the published modules. That replaces the KOTLIN_1_9 settings that were spread over about 40 build files, and the unused kotlin-compatible-version catalog entry. sentry-spring-7 was already on 2.1.
    • Test code, samples and sentry-test-support aren't published, so they keep the compiler's default (2.4). For the Android unit tests that's up from 2.1, so navigation3's BackStackConverterTest now needs an explicit arrayOf<Any> to pass a newer check on reified intersection types.
  • stdlib: the modules that declare kotlin-stdlib-jdk8 (replay, sqlite, timber, distribution, okhttp, ktor-client) pin it at 2.1.21, up from 1.9.24. The other Kotlin modules (compose, fragment, navigation, navigation3, apollo, kotlin-extensions) declare no stdlib and use the app's own. That's safe on a Kotlin 2.0 app's stdlib: none of our classes reference stdlib API newer than 1.9.24.
    • sentry-compose's coreLibrariesVersion is removed. With kotlin.stdlib.default.dependency=false it never reached the published metadata.
    • I kept the -jdk8 artifact on purpose. At 2.1.21 it's an empty artifact that depends on kotlin-stdlib. It also pulls up any older stdlib-jdk8 coming from other libraries, so Java-only apps (which don't get the Kotlin Gradle plugin's version alignment) don't end up with duplicate classes.
  • Version warnings: Kotlin 2.4 deprecates 2.1, so the io.sentry.jdk-target convention adds -Xsuppress-version-warnings to every Kotlin compilation.
  • KGP 2.4 fixes, taken from build: Bump Kotlin to 2.4.21 and the language/API version to 2.0 #6487:
    • Kotlin module names stay the project name. KGP 2.4 prefixes them with the group, and the colon in that name ends up in .kotlin_module file names, which app bundles reject.
    • ABI validation is enabled through the new abiValidation {} DSL.
    • API dumps: getEntries() is added on the fragment enum, and the dumper no longer lists synthetic constructors (sqlite, navigation3).
    • The size test gets a -dontwarn for kotlin.jvm.JvmField.
    • sentry-compose tests type their LayoutNode/Owner locals explicitly. Without that, K2 compiles them to error.NonExistentClass. This also covers a test that was added after build: Bump Kotlin to 2.4.21 and the language/API version to 2.0 #6487.

The published classes now carry metadata version 2.1.0.

Issues

💡 Motivation and Context

  • Kotlin 2.4 rejects language/API 1.9, and AGP 9.6.0-alpha04 pulls in KGP 2.4.20. So 1.9 can't be built on AGP 9.6, with or without built-in Kotlin.
  • AGP 10 removes the android.builtInKotlin=false opt-out.
  • We chose 2.1 over 2.2 because 2.2 would break apps on Kotlin 2.0.x, who can still use every current stable Google library. The cost is that 9.x stays on Kotlin 2.4, because Kotlin 2.5 (December 2026) drops language 2.0 and 2.1.

Replaces #6487, which targeted 2.0.

💚 How did you test it?

  • make format api, then assemble, compileTestKotlin, compileReleaseUnitTestKotlin and compileTestKotlinDesktop across the build.
  • Unit tests for every module with Kotlin sources: replay, navigation3, sqlite, fragment, timber, navigation, distribution, compose, okhttp, apollo/apollo-3/4/5, kotlin-extensions, ktor-client.
  • Checked mv=[2,1,0] in published classes.
  • UI tests on an API 36.1 emulator, the real check for replay masking and sentry-compose's @Suppress("INVISIBLE_REFERENCE") access under K2:
    • ./scripts/test-ui-critical.sh: 3/3 Maestro flows pass.
    • sentry-uitest-android: 35/35 pass, including ReplayTest, ReplaySnapshotTest and the Compose click and swipe tests.
  • R8 works on AGP 8.0.2 and 8.4.2. A minified Kotlin 2.0.0 app and a Java-only app, both with sentry-android and sentry-okhttp, build and run.
    • If an app keeps kotlin.Metadata (for example for kotlin-reflect), R8 in AGP 8.0–8.5 prints about 400 warnings: An error occurred when parsing kotlin metadata. This normally happens when using a newer version of kotlin than the kotlin version released when this version of R8 was created. That happens because it can't read the 2.1 metadata. The build still succeeds, and AGP 8.6 prints none. This belongs in the 9.0 migration guide.

📝 Checklist

  • I added GH Issue ID & Linear ID
  • I added tests to verify the changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • I updated the docs if needed.
  • I updated the wizard if needed.
  • Review from the native team if needed.
  • No breaking change or entry added to the changelog.
  • No breaking change for hybrid SDKs or communicated to hybrid SDKs.
  • Public API changes reviewed by another Mobile SDK team member or implemented according to the develop docs spec.

🔮 Next steps

  • Tell the hybrid SDK teams. React Native 0.73–0.76 default templates (Kotlin 1.8–1.9) and Capacitor 6/7 apps that compile Kotlin will need Kotlin 2.0+.
  • Add "Minimum Kotlin: 2.0" to sentry-docs and the 9.0 migration guide.
  • Add a CI fixture that compiles a small app on Kotlin 2.0 against our artifacts.
  • Before 9.0 GA, move sentry-compose to com.android.kotlin.multiplatform.library.

🤖 Generated with Claude Code

runningcode and others added 2 commits November 17, 2026 18:16
Kotlin 2.4 rejects language and API version 1.9, and AGP 9.6 pulls in
KGP 2.4.20, so 1.9 can no longer be built. The Kotlin modules now target
2.1 and depend on kotlin-stdlib 2.1.21. Apps that compile Kotlin need
Kotlin 2.0 or newer, up from 1.8, the same minimum as stable AndroidX
and Firebase. Kotlin 2.4 deprecates 2.1, so the version warning is
suppressed.

KGP 2.4 prefixes Kotlin module names with the group, and R8 copies the
colon into .kotlin_module entry names, which app bundles reject, so
module names stay the project name. KGP 2.4 also replaced the
experimental ABI validation DSL, so enable it through abiValidation {}.
Its dumper no longer lists synthetic constructors, which drops lines
from the sqlite and navigation3 dumps.

Compiling at 2.1 uses K2, which adds getEntries() to Kotlin enums,
references kotlin.jvm.JvmField from Compose $stable fields, and compiles
locals of suppressed internal Compose types to error.NonExistentClass,
so those test locals are typed explicitly.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sentry

sentry Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

📲 Install Builds

Android

🔗 App Name App ID Version Configuration
SDK Size io.sentry.tests.size 8.64.0 (1) release

⚙️ sentry-android Build Distribution Settings

@linear-code

linear-code Bot commented Nov 18, 2026

Copy link
Copy Markdown

JAVA-826

The 9.0.0 warning block now names Kotlin next to Java and Android, and
links the Kotlin bullet to the tracking issue like the other two bullets.

Refs #6473

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added risk: high PR risk score: high and removed risk: high PR risk score: high labels Nov 18, 2026
runningcode and others added 2 commits November 18, 2026 11:50
…vention

The io.sentry.jdk-target convention now sets language/API version 2.1 for
the main Kotlin compilations of every published module. That replaces the
settings spread over about 40 build files and the unused
kotlin-compatible-version catalog entry.

Test code isn't published, so it keeps the compiler's default. That moves
the Android and multiplatform unit tests from 2.1 to 2.4, where
BackStackConverterTest needs an explicit array type to pass the newer
reified intersection type check. Samples and sentry-test-support aren't
published either, so they use the default too.

sentry-compose's coreLibrariesVersion is removed. With
kotlin.stdlib.default.dependency=false it never reached the published
metadata.

Refs #6473

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Only the modules that declare kotlin-stdlib pin 2.1.21. The others use the
app's own stdlib.

Refs #6473

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added risk: high PR risk score: high and removed risk: high PR risk score: high labels Nov 18, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: high PR risk score: high

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant