Skip to content

fix(ndk_flutter): migrate Android plugin to Built-in Kotlin - #692

Closed
nogringo wants to merge 1 commit into
masterfrom
fix/ndk-flutter-built-in-kotlin
Closed

fix(ndk_flutter): migrate Android plugin to Built-in Kotlin#692
nogringo wants to merge 1 commit into
masterfrom
fix/ndk-flutter-built-in-kotlin

Conversation

@nogringo

@nogringo nogringo commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

Apply the Kotlin Gradle Plugin only on AGP < 9 so Flutter 3.44+ stops flagging ndk_flutter as applying KGP and future Flutter versions keep building. The conditional stays on one line so Flutter's source-level detection does not re-trigger the warning. Replace the deprecated kotlinOptions block with kotlin { compilerOptions }, which also works under AGP 9. Remains compatible with Flutter < 3.44.

Summary by CodeRabbit

  • Bug Fixes
    • Improved Android build compatibility with newer tooling versions.
    • Updated Kotlin compilation settings to use a consistent JVM 17 target.

Apply the Kotlin Gradle Plugin only on AGP < 9 so Flutter 3.44+ stops
flagging ndk_flutter as applying KGP and future Flutter versions keep
building. The conditional stays on one line so Flutter's source-level
detection does not re-trigger the warning. Replace the deprecated
kotlinOptions block with kotlin { compilerOptions }, which also works
under AGP 9. Remains compatible with Flutter < 3.44.
@nogringo
nogringo requested review from 1-leo and frnandu July 6, 2026 00:42
@nogringo nogringo self-assigned this Jul 6, 2026
@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The Android Gradle build script for ndk_flutter now conditionally applies the Kotlin Android plugin based on the AGP major version (skipped when AGP major version is 9 or above), and relocates JVM target configuration from android.kotlinOptions to a new top-level kotlin { compilerOptions } block set to JVM_17.

Changes

Gradle Kotlin Configuration Update

Layer / File(s) Summary
Conditional plugin application and JVM target relocation
packages/ndk_flutter/android/build.gradle
Kotlin Android plugin is now applied only when AGP major version is below 9; android.kotlinOptions.jvmTarget is removed and replaced with a top-level kotlin { compilerOptions { jvmTarget = JvmTarget.JVM_17 } } block.

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

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: migrating the ndk_flutter Android plugin to built-in Kotlin handling.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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
  • Commit unit tests in branch fix/ndk-flutter-built-in-kotlin

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/ndk_flutter/android/build.gradle`:
- Around line 24-28: Update the build logic in build.gradle so the Kotlin plugin
is applied not only for AGP versions below 9, but also whenever
android.builtInKotlin is explicitly false. Use the existing agpMajor check and
the kotlin-android application block to add a built-in Kotlin opt-out condition,
ensuring this module still applies KGP when a consumer disables Flutter built-in
Kotlin.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 5545ffc2-b4b3-4b92-9a99-44d46a26151b

📥 Commits

Reviewing files that changed from the base of the PR and between 473a870 and f5d2d52.

📒 Files selected for processing (1)
  • packages/ndk_flutter/android/build.gradle

Comment on lines +24 to +28

// AGP 9+ bundles Kotlin (Flutter Built-in Kotlin); only apply KGP ourselves on older AGP.
// Must stay on one line: Flutter's detection flags any line starting with `apply plugin: 'kotlin-android'`.
def agpMajor = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')[0] as int
if (agpMajor < 9) { apply plugin: 'kotlin-android' }

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🌐 Web query:

Does android.builtInKotlin=false gradle property require kotlin-android plugin in library subprojects on AGP 9?

💡 Result:

Yes, if you set android.builtInKotlin=false in your gradle.properties file, you are effectively disabling the built-in Kotlin support provided by the Android Gradle Plugin (AGP) 9.0 [1]. Consequently, you must apply the kotlin-android plugin in your library subprojects (and any other modules) to compile Kotlin code, as the built-in functionality is no longer active to handle that task [1][2]. The android.builtInKotlin=false flag is intended as a temporary opt-out mechanism for projects that cannot immediately migrate to AGP 9.0's built-in Kotlin support due to conflicts or specific configuration needs [1][2]. When this property is set to false, AGP reverts to the previous behavior where it relies on the separately applied kotlin-android plugin for Kotlin compilation [1]. You should remove this flag once you have resolved the underlying issues and migrated to built-in Kotlin [3][1]. In AGP 9.0, built-in Kotlin is enabled by default, which removes the need to apply the kotlin-android plugin manually in those modules [3][1].

Citations:


Honor the android.builtInKotlin=false escape hatch.
AGP 9+ only skips kotlin-android when built-in Kotlin is enabled; if a consumer opts out with android.builtInKotlin=false, this module still needs the plugin or Kotlin compilation will fail.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/ndk_flutter/android/build.gradle` around lines 24 - 28, Update the
build logic in build.gradle so the Kotlin plugin is applied not only for AGP
versions below 9, but also whenever android.builtInKotlin is explicitly false.
Use the existing agpMajor check and the kotlin-android application block to add
a built-in Kotlin opt-out condition, ensuring this module still applies KGP when
a consumer disables Flutter built-in Kotlin.

@codecov

codecov Bot commented Jul 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 71.90%. Comparing base (473a870) to head (f5d2d52).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #692      +/-   ##
==========================================
- Coverage   71.93%   71.90%   -0.04%     
==========================================
  Files         212      212              
  Lines       11018    11018              
==========================================
- Hits         7926     7922       -4     
- Misses       3092     3096       +4     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@frnandu

frnandu commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

I did this on #679 , please review it so we can merge it and move on to work on other things.

@nogringo nogringo closed this Jul 6, 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