diff --git a/packages/react-native-executorch-webrtc/android/build.gradle b/packages/react-native-executorch-webrtc/android/build.gradle index 919f9d2666..da727c1f6d 100644 --- a/packages/react-native-executorch-webrtc/android/build.gradle +++ b/packages/react-native-executorch-webrtc/android/build.gradle @@ -13,7 +13,13 @@ buildscript { } apply plugin: 'com.android.library' -apply plugin: 'kotlin-android' +// AGP 9 ships built-in Kotlin support and registers the `kotlin` extension +// itself. Applying the Kotlin plugin on top of it fails configuration with +// "Cannot add extension with name 'kotlin'". Only apply it when nothing has +// registered that extension yet. +if (project.extensions.findByName('kotlin') == null) { + apply plugin: 'kotlin-android' +} android { namespace 'com.executorch.webrtc' @@ -51,9 +57,11 @@ android { targetCompatibility JavaVersion.VERSION_17 } - kotlinOptions { - jvmTarget = '17' - } + // No `kotlinOptions` block: it comes from the Kotlin plugin, which is not + // applied on AGP 9, so referencing it there fails with "Could not find + // method kotlinOptions()". Both AGP 8 and AGP 9 take the Kotlin jvmTarget + // from `compileOptions` above; verified to emit Java 17 bytecode on + // AGP 8.13.2 and AGP 9.4.0. packaging { jniLibs { diff --git a/packages/react-native-executorch/android/build.gradle.kts b/packages/react-native-executorch/android/build.gradle.kts index 4b8ff5ca66..01d75e11be 100644 --- a/packages/react-native-executorch/android/build.gradle.kts +++ b/packages/react-native-executorch/android/build.gradle.kts @@ -2,10 +2,18 @@ import groovy.json.JsonSlurper plugins { id("com.android.library") - id("org.jetbrains.kotlin.android") + // Kept on the classpath but not applied here: AGP 9 ships built-in Kotlin + // support and registers the `kotlin` extension itself, so applying the + // Kotlin plugin on top fails with "Cannot add extension with name + // 'kotlin'". Applied conditionally below instead. + id("org.jetbrains.kotlin.android") apply false id("com.facebook.react") } +if (project.extensions.findByName("kotlin") == null) { + apply(plugin = "org.jetbrains.kotlin.android") +} + /** * Helper function to get variables from the root project (App level) * or fall back to local project properties. @@ -116,9 +124,11 @@ android { targetCompatibility = JavaVersion.VERSION_17 } - kotlinOptions { - jvmTarget = "17" - } + // No `kotlinOptions` block: its type-safe accessor is generated only when + // the Kotlin plugin is applied from the `plugins` block, which it no longer + // always is. Both AGP 8 and AGP 9 take the Kotlin jvmTarget from + // `compileOptions` above; verified to emit Java 17 bytecode on AGP 8.13.2 + // and AGP 9.4.0. } repositories {