From 8d5ce9dee22e79985361df527ed06fcf9221b120 Mon Sep 17 00:00:00 2001 From: Gabriel Donadel Dall'Agnol Date: Sat, 5 Sep 2026 09:07:34 -0700 Subject: [PATCH] fix(android): skip explicit Kotlin plugin when AGP registers the kotlin extension AGP 9 ships built-in Kotlin support and registers the kotlin extension itself. Applying the Kotlin plugin again fails configuration with "Cannot add extension with name 'kotlin'". Check for the extension directly, which needs no AGP version table and covers AGP 10, where the android.builtInKotlin opt-out is removed. --- packages/react-native-nitro-image/android/build.gradle | 9 ++++++++- .../react-native-nitro-web-image/android/build.gradle | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/packages/react-native-nitro-image/android/build.gradle b/packages/react-native-nitro-image/android/build.gradle index 8f83cbe3..b17f65ec 100644 --- a/packages/react-native-nitro-image/android/build.gradle +++ b/packages/react-native-nitro-image/android/build.gradle @@ -19,7 +19,14 @@ def isNewArchitectureEnabled() { } apply plugin: "com.android.library" -apply plugin: 'org.jetbrains.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: 'org.jetbrains.kotlin.android' +} + apply from: '../nitrogen/generated/android/NitroImage+autolinking.gradle' apply from: "./fix-prefab.gradle" diff --git a/packages/react-native-nitro-web-image/android/build.gradle b/packages/react-native-nitro-web-image/android/build.gradle index 109cb675..2e21243b 100644 --- a/packages/react-native-nitro-web-image/android/build.gradle +++ b/packages/react-native-nitro-web-image/android/build.gradle @@ -19,7 +19,14 @@ def isNewArchitectureEnabled() { } apply plugin: "com.android.library" -apply plugin: 'org.jetbrains.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: 'org.jetbrains.kotlin.android' +} + apply from: '../nitrogen/generated/android/NitroWebImage+autolinking.gradle' if (isNewArchitectureEnabled()) {