From 3018ef6c6a8642f56570f5cc13f3d282c8c8b7eb Mon Sep 17 00:00:00 2001 From: Zita Szupera Date: Tue, 8 Sep 2026 11:30:53 +0200 Subject: [PATCH] fix(android): set the Kotlin jvmTarget without requiring the Kotlin Gradle plugin --- package/expo-package/android/build.gradle | 15 +++++++++------ package/native-package/android/build.gradle | 15 +++++++++------ 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/package/expo-package/android/build.gradle b/package/expo-package/android/build.gradle index e517fc9dfa..5e231ac5dc 100644 --- a/package/expo-package/android/build.gradle +++ b/package/expo-package/android/build.gradle @@ -69,16 +69,13 @@ android { } compileOptions { - // Must match the Kotlin jvmTarget below. AGP 9 (React Native 0.87) fails the build on an - // inconsistent JVM-target between the Java and Kotlin compilation tasks. + // Must match the Kotlin jvmTarget set on the KotlinCompile tasks below: an inconsistent + // JVM-target between the Java and Kotlin compilation tasks fails the build. On AGP 9 this + // is also what AGP's built-in Kotlin derives the Kotlin jvmTarget from. sourceCompatibility JavaVersion.VERSION_17 targetCompatibility JavaVersion.VERSION_17 } - kotlinOptions { - jvmTarget = "17" - } - sourceSets { main { if (isNewArchitectureEnabled()) { @@ -128,6 +125,12 @@ tasks.matching { it.name == "preBuild" }.configureEach { tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach { dependsOn("syncSharedShimmerSources") + // Set here rather than via `android.kotlinOptions`: that DSL is contributed by the Kotlin + // Gradle plugin, which is deliberately not applied when AGP registers the `kotlin` + // extension itself (see the guard at the top of this file). This form works either way. + compilerOptions { + jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17 + } } repositories { diff --git a/package/native-package/android/build.gradle b/package/native-package/android/build.gradle index be804ad0f3..11d3af6763 100644 --- a/package/native-package/android/build.gradle +++ b/package/native-package/android/build.gradle @@ -79,16 +79,13 @@ android { } compileOptions { - // Must match the Kotlin jvmTarget below. AGP 9 (React Native 0.87) fails the build on an - // inconsistent JVM-target between the Java and Kotlin compilation tasks. + // Must match the Kotlin jvmTarget set on the KotlinCompile tasks below: an inconsistent + // JVM-target between the Java and Kotlin compilation tasks fails the build. On AGP 9 this + // is also what AGP's built-in Kotlin derives the Kotlin jvmTarget from. sourceCompatibility JavaVersion.VERSION_17 targetCompatibility JavaVersion.VERSION_17 } - kotlinOptions { - jvmTarget = "17" - } - sourceSets { main { if (isNewArchitectureEnabled()) { @@ -141,6 +138,12 @@ tasks.matching { it.name == "preBuild" }.configureEach { tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach { dependsOn("syncSharedShimmerSources") + // Set here rather than via `android.kotlinOptions`: that DSL is contributed by the Kotlin + // Gradle plugin, which is deliberately not applied when AGP registers the `kotlin` + // extension itself (see the guard at the top of this file). This form works either way. + compilerOptions { + jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17 + } } repositories {