fix(ndk_flutter): migrate Android plugin to Built-in Kotlin - #692
fix(ndk_flutter): migrate Android plugin to Built-in Kotlin#692nogringo wants to merge 1 commit into
Conversation
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.
📝 WalkthroughWalkthroughThe 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 ChangesGradle Kotlin Configuration Update
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (1)
packages/ndk_flutter/android/build.gradle
|
|
||
| // 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' } |
There was a problem hiding this comment.
🗄️ 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:
- 1: https://developer.android.google.cn/build/migrate-to-built-in-kotlin
- 2: https://github.com/Kotlin/kotlin-agent-skills/blob/main/skills/kotlin-tooling-agp9-migration/references/KNOWN-ISSUES.md
- 3: https://developer.android.com/build/migrate-to-built-in-kotlin
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 Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
|
I did this on #679 , please review it so we can merge it and move on to work on other things. |
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