Skip to content

fix(android): skip explicit Kotlin plugin when AGP registers the kotlin extension - #569

Merged
huextrat merged 1 commit into
mainfrom
codex/fix-agp9-built-in-kotlin
Sep 7, 2026
Merged

fix(android): skip explicit Kotlin plugin when AGP registers the kotlin extension#569
huextrat merged 1 commit into
mainfrom
codex/fix-agp9-built-in-kotlin

Conversation

@huextrat

@huextrat huextrat commented Sep 7, 2026

Copy link
Copy Markdown
Owner

Problem

Android Gradle Plugin 9 ships with built-in Kotlin support and registers the kotlin extension itself. When this library also applies kotlin-android unconditionally, Gradle configuration fails before compilation:

> Failed to apply plugin 'kotlin-android'.
   > Cannot add extension with name 'kotlin', as there is an extension already registered with that name.

Consumers should not need to disable AGP's built-in Kotlin support project-wide just to build this dependency, especially because that opt-out is removed in AGP 10.

Change

Apply kotlin-android only when no kotlin extension has already been registered:

if (project.extensions.findByName('kotlin') == null) {
  apply plugin: "kotlin-android"
}

The guard runs immediately after com.android.library, so AGP has already had a chance to register its extension.

AGP Built-in Kotlin kotlin extension Explicit plugin apply
8.x unavailable/off absent yes (unchanged)
9.x enabled registered by AGP no
9.x disabled absent yes
10+ enabled registered by AGP no

Verification

  • ./gradlew :react-native-rate-app:compileDebugKotlin with AGP 9.2.1 and Gradle 9.3.1
  • Same compilation with -Pandroid.newDsl=false -Pandroid.builtInKotlin=false
  • yarn lint
  • yarn test --maxWorkers=2 --coverage --no-watchman (22 tests, 100% coverage)
  • yarn prepare

Adapted from huextrat/react-native-screenshot-aware#613.

@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown

Coverage report

St.
Category Percentage Covered / Total
🟢 Statements 100% 55/55
🟢 Branches 100% 28/28
🟢 Functions 100% 9/9
🟢 Lines 100% 55/55

Test suite run success

22 tests passing in 2 suites.

Report generated by 🧪jest coverage report action from 9580078

@huextrat
huextrat merged commit 799f2e4 into main Sep 7, 2026
5 checks passed
@huextrat
huextrat deleted the codex/fix-agp9-built-in-kotlin branch September 7, 2026 08:28
huextrat pushed a commit that referenced this pull request Sep 7, 2026
## [2.1.3](v2.1.2...v2.1.3) (2026-09-07)

### Bug Fixes

* **android:** skip explicit Kotlin plugin when AGP registers the kotlin extension ([#569](#569)) ([799f2e4](799f2e4))
@huextrat

huextrat commented Sep 7, 2026

Copy link
Copy Markdown
Owner Author

🎉 This PR is included in version 2.1.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant