Skip to content

fix(android): drop the unused kotlin-android plugin - #644

Open
gabrieldonadel wants to merge 2 commits into
googlemaps:mainfrom
gabrieldonadel:fix/agp9-built-in-kotlin-googlemaps
Open

gabrieldonadel wants to merge 2 commits into
googlemaps:mainfrom
gabrieldonadel:fix/agp9-built-in-kotlin-googlemaps

Conversation

@gabrieldonadel

@gabrieldonadel gabrieldonadel commented Sep 5, 2026

Copy link
Copy Markdown

Problem

Android Gradle Plugin 9 ships built-in Kotlin support and enables it by default, so
AGP registers the kotlin extension itself. When a library also applies kotlin-android
explicitly, the two collide and configuration fails before anything compiles:

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

The apply is unconditional in this file, so on an AGP 9 project this module cannot be
built at all.

Change

Remove the kotlin-android apply.

 apply plugin: 'com.android.library'
-apply plugin: 'kotlin-android'
 apply plugin: 'com.facebook.react'

Files changed:

  • android/build.gradle

This PR originally guarded the apply behind a check for the kotlin extension. At
@jokerttu's suggestion it now removes the line instead, which is the better fix here:
the module has no Kotlin to compile, so the plugin was doing nothing on any AGP version.

Why removal is safe in this module

  • android/src holds 33 .java files and no .kt files. The only Kotlin in the
    repository is under example/android/app, which is a separate Gradle project with its
    own build file and is unaffected.
  • Android codegen emits Java here — codegenConfig sets android.javaPackageName — so
    the generated/java and generated/jni directories added to sourceSets.main.java.srcDirs
    contain no Kotlin either.
  • Nothing else in android/build.gradle depends on the Kotlin plugin: no kotlinOptions
    block, no Kotlin stdlib dependency, no kotlin.srcDirs.

Because there are no Kotlin sources, this is a no-op on AGP 8 as well as a fix on AGP 9 —
compileDebugKotlin had nothing to do before and does not exist now.

What I verified, and what I did not

  • Inventoried the module's sources and checked every Kotlin-dependent construct listed
    above.
  • The changed file passes a Groovy Phases.CONVERSION syntax check.
  • Not run: this repo's own CI or the example app. A CI run is the real confirmation
    and I could not do that from outside.

Found while sweeping popular React Native libraries for AGP 9 new-DSL compatibility,
where this collision was by far the most common blocker. Most libraries do have Kotlin
sources and need the guard; this one does not, and is better off without the plugin.

…in 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.
@google-cla

google-cla Bot commented Sep 5, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@gabrieldonadel

Copy link
Copy Markdown
Author

@googlebot I signed it!

@jokerttu jokerttu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the report; the collision is real.
I'd rather fix it at the root than guard it, though.
See the suggestion.

Comment thread android/build.gradle Outdated
Per maintainer review: this module has no Kotlin sources, so the guard is
unnecessary and the apply can simply be removed. The library module holds 33
.java files and no .kt files; the only Kotlin in the repo lives in
example/android/app, which is a separate Gradle project with its own build
file. Android codegen emits Java here, per the javaPackageName in
codegenConfig. Nothing else in this build file depends on the Kotlin plugin --
there is no kotlinOptions block and no Kotlin stdlib dependency.

Co-authored-by: gabrieldonadel <11707729+gabrieldonadel@users.noreply.github.com>
@gabrieldonadel gabrieldonadel changed the title fix(android): skip explicit Kotlin plugin when AGP registers the kotlin extension fix(android): drop the unused kotlin-android plugin Sep 15, 2026
@gabrieldonadel

Copy link
Copy Markdown
Author

Agreed — you're right, and removing it is the better fix here. Applied in ee9db75; the
PR is now a one-line deletion.

I checked the module before taking it, since the guard is the right answer in most of the
libraries in this sweep and I wanted to be sure this one is genuinely different:

  • android/src has 33 .java files and no .kt files. The only Kotlin in the repo is
    under example/android/app, which is a separate Gradle project with its own build file.
  • codegenConfig sets android.javaPackageName, so codegen emits Java — the
    generated/java and generated/jni directories added to sourceSets.main.java.srcDirs
    bring no Kotlin in either.
  • Nothing else in android/build.gradle needs the plugin: no kotlinOptions, no Kotlin
    stdlib dependency, no kotlin.srcDirs.

So the plugin was a no-op on AGP 8 too, not just redundant on AGP 9. Title and description
updated to describe the removal rather than the guard.

Worth flagging one thing for whenever you do move this module to Kotlin: under AGP 9,
built-in Kotlin does not read java.srcDirs for Kotlin sources. The generated/java and
generated/jni entries in your sourceSets block would need mirroring into
kotlin.srcDirs at that point, or the files get dropped silently and the build fails with
Unresolved reference. Not an issue today with no Kotlin in the module.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants