Skip to content

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

Closed
gabrieldonadel wants to merge 1 commit into
clerk:mainfrom
gabrieldonadel:fix/agp9-built-in-kotlin
Closed

fix(android): skip explicit Kotlin plugin when AGP registers the kotlin extension#9660
gabrieldonadel wants to merge 1 commit into
clerk:mainfrom
gabrieldonadel:fix/agp9-built-in-kotlin

Conversation

@gabrieldonadel

Copy link
Copy Markdown
Contributor

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. AGP
words it two ways, both the same problem:

> Failed to apply plugin 'kotlin-android'.
   > Cannot add extension with name 'kotlin', as there is an extension already registered with that name.
> The 'kotlin-android' plugin is no longer required for Kotlin support since AGP 9.0.

The apply is unconditional in all 2 modules below, so on an AGP 9 project this cannot be built
at all. There is no consumer-side workaround short of patching the file — setting
android.builtInKotlin=false project-wide just to build one dependency is not a
reasonable ask, and that escape hatch is removed in AGP 10.

Change

Apply the plugin only when nothing has registered the kotlin extension yet:

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

Files changed:

  • packages/expo-google-signin/android/build.gradle
  • packages/expo-passkeys/android/build.gradle

This tests the condition that actually fails, so there is no AGP version table to
keep in sync, and it covers AGP 10 — where the android.builtInKotlin opt-out is
removed — without a special case.

AGP android.builtInKotlin kotlin extension explicit apply
8.x unset or false absent yes (unchanged)
9.x unset or true registered by AGP no
9.x false absent yes
10+ n/a (removed) registered by AGP no

The guard sits after apply plugin: 'com.android.library' in every file it touches,
so AGP has already registered its extensions by the time it runs. I checked that
ordering per file rather than assuming it.

What I verified, and what I did not

  • Verified end to end on a real Expo SDK 58 / React Native 0.87 project with AGP
    9.2.1 and Gradle 9.4.1: :app:assembleDebug succeeds both with
    -Pandroid.newDsl=true -Pandroid.builtInKotlin=true and with both flags off.
  • Confirmed both branches actually execute rather than one path always winning: with
    the flags off, compileDebugKotlin runs from the explicitly applied plugin; with
    them on the build completes without it.
  • Every changed file passes a Groovy Phases.CONVERSION syntax check.
  • Not run: this repo's own CI or example app.

Where this came from

A sweep of 500 popular React Native libraries against the AGP 9 defaults. 152 failed
with the new DSL enabled, and 144 of those failed on exactly this collision — by
far the most common blocker. Affects @clerk/expo-google-signin, @clerk/expo-passkeys here.

The same guard shape was accepted in
RevenueCat/react-native-purchases#1934,
at that maintainer's suggestion.

…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.
@vercel

vercel Bot commented Sep 4, 2026

Copy link
Copy Markdown

@gabrieldonadel is attempting to deploy a commit to the Clerk Production Team on Vercel.

A member of the Team first needs to authorize it.

@changeset-bot

changeset-bot Bot commented Sep 4, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 64680a7

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai

coderabbitai Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Organization UI (inherited)

Review profile: ASSERTIVE

Plan: Team

Run ID: 17cfffe2-e3da-427f-9f1a-f1552920fede

📥 Commits

Reviewing files that changed from the base of the PR and between 65342c6 and 64680a7.

📒 Files selected for processing (2)
  • packages/expo-google-signin/android/build.gradle
  • packages/expo-passkeys/android/build.gradle
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • clerk/clerk_go (manual)
  • clerk/dashboard (manual)
  • clerk/accounts (manual)
  • clerk/backoffice (manual)
  • clerk/clerk (manual)

Included review availability: Your plan provides up to 4 included reviews per hour; 3 remain after this review.


📝 Walkthrough

Walkthrough

The Android build scripts for Expo Google Sign-In and Expo Passkeys now check for an existing kotlin extension. Each script applies kotlin-android only when the extension is absent, preventing duplicate-extension configuration failures under AGP 9.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 64680

The Android modules avoid duplicate Kotlin extension registration while retaining Kotlin plugin application where needed. No current merge-blocking risk remains.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: skipping the explicit Kotlin plugin when AGP registers the Kotlin extension.
Description check ✅ Passed The description directly explains the AGP 9 Kotlin extension conflict, the conditional plugin application, affected files, verification steps, and limitations.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 0…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch

Warning

Linked repositories: Your configuration references 7 linked repositories, but your current plan allows 5. Analyzed clerk/clerk_go, clerk/dashboard, clerk/accounts, clerk/backoffice, clerk/clerk, skipped clerk/clerk-docs, clerk/cloudflare-workers.


Comment @coderabbitai help to get the list of available commands.

@wobsoriano

Copy link
Copy Markdown
Member

Thanks for this! Closing in favor of #9662, which is the same change so our full CI runs on it. Added you as co-author.

@wobsoriano wobsoriano closed this Sep 4, 2026
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.

2 participants