Skip to content

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

Merged
nickolas-dimitrakas merged 1 commit into
ROKT:mainfrom
gabrieldonadel:fix/agp9-built-in-kotlin
Sep 10, 2026
Merged

nickolas-dimitrakas merged 1 commit into
ROKT: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 this module, 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:

  • Rokt.Widget/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 @rokt/react-native-sdk 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.
@gabrieldonadel
gabrieldonadel requested a review from a team as a code owner September 4, 2026 15:25

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@pr-security-agent

Copy link
Copy Markdown

🔒 Security Scan Complete

✅ No security issues detected

Scanned files against 45 rules. · Reviewed commit: 277f28de93

📜 Scan history (1 scan)
Commit Time (UTC) Status Findings
277f28d 2026-09-04 15:25:40 ✅ success 0
ℹ️ About PR Security Agent

This scan was performed by PR Security Agent, an automated security review tool for pull requests. See the User Guide for details on severity levels, feedback reactions, and scan configuration.

Reply @pr-security-agent help for the list of commands you can run on this PR.

@paved-road-agent

Copy link
Copy Markdown

🛣️ Rokt Platform Paved Roads Scan Complete

✅ No paved-road issues detected

Scanned files against 2 rules. · Reviewed commit: 277f28de93

📜 Scan history (1 scan)
Commit Time (UTC) Status Findings
277f28d 2026-09-04 15:25:41 ✅ success 0
ℹ️ About Rokt Platform Paved Roads Agent

This scan was performed by the Rokt Platform Paved Roads Agent, an automated paved-road standards review tool for pull requests. See the User Guide for details on severity levels, feedback reactions, and scan configuration.

Reply @paved-road-agent help for the list of commands you can run on this PR.

@coderabbitai

coderabbitai Bot commented Sep 4, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Enterprise

Run ID: 87cbf3c6-dc57-4548-9731-91fd290e9b23

📥 Commits

Reviewing files that changed from the base of the PR and between 3049c46 and 277f28d.

📒 Files selected for processing (1)
  • Rokt.Widget/android/build.gradle
🔗 Linked repositories identified

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

  • ROKT/cassandra (manual)
  • ROKT/kafka-configs (manual)
  • ROKT/kafka (manual)
  • ROKT/kafka-connect (manual)
  • ROKT/aws-eks (manual)

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


📝 Walkthrough

Walkthrough

The Android build script now checks for an existing kotlin extension before applying the kotlin-android plugin. This supports AGP 9’s built-in Kotlin support.

Changes

Android build configuration

Layer / File(s) Summary
Conditional Kotlin plugin application
Rokt.Widget/android/build.gradle
The script applies kotlin-android only when the kotlin extension is not already registered.

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

Merge Risk: ⚪ Minimal · up to 277f2

The Android build now skips explicit Kotlin plugin application when Kotlin support is already registered, avoiding AGP extension collisions while retaining the existing fallback behavior. The change is ready to merge.

Suggested reviewers: alexs-mparticle

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: conditionally skipping the explicit Kotlin plugin when AGP registers the kotlin extension.
Description check ✅ Passed The description provides detailed background, explains the code change, documents compatibility behavior, records verification results, and identifies testing that was not performed. It does not use t…
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
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@nickolas-dimitrakas
nickolas-dimitrakas merged commit 4b9b2d2 into ROKT:main Sep 10, 2026
8 of 9 checks passed
@rokt-releases rokt-releases Bot mentioned this pull request Oct 26, 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