Migrate off legacy Kotlin Gradle Plugin apply per the built-in-Kotlin migration (#636) - #643
Conversation
…lutton#636) Flutter 3.44+ deprecates plugins that apply KGP themselves, and AGP 9 removes support for it (built-in Kotlin). Per the official plugin-author migration guide (https://docs.flutter.dev/release/breaking-changes/migrate-to-built-in-kotlin/for-plugin-authors), apply kotlin-android only when the consuming app's AGP major version is below 9, and replace the android.kotlinOptions block with the kotlin.compilerOptions DSL (requires KGP >= 2.0, already satisfied by kotlin_version 2.2.20). The conditional keeps the plugin buildable for apps on older stable Flutter/AGP versions.
|
I tested this patch against a real app on AGP 9 — build and runtime — and wanted Environment
Baseline — 4.2.5 unpatched, The build fails, exactly as the migration guide predicts: With this PR applied, The build succeeds: So the patch does fix the actual breakage under built-in Kotlin. 👍 However, the Flutter warning is still emitted My guess is that Flutter's check is a static scan of the plugin's
If that's right, fully clearing the warning would also mean making the Runtime check I also installed the patched release build on an emulator (Android 16, x86_64, Audio was actually rendered, and the progress callbacks fired continuously — Either way, the functional fix here is the part that matters for AGP 9 users |
|
Thank you for this — and especially for the runtime pass. Nobody had verified this end to end on a device before you did. Before the warning, though: there is a configuration you have not tested that I think may be broken by this PR, and you are the only person with a rig that can check it. You tested
flutter/flutter#190339 is where I got this. Its author hit that failure on purpose: he tried making I have not been able to run it: no AGP 9 rig here. So that is a reading of the source, not a result, and I could be wrong — I searched flutter/flutter for that error string and found only #190339 itself, no in-the-wild report. But if it does fail for you, it is worth knowing before this merges, and it would be a real bug in the patch rather than a cosmetic warning. On the warning itself — you were right about the mechanism. One correction, and it saves you a build: the I do not think there is a follow-up commit worth your time here. This file is already the migration guide's own "Support Flutter versions earlier than 3.44" snippet, verbatim — and that snippet matches the regex too. It is a false positive on AGP 9+, where the guard is false and KGP is never applied. It is already filed: flutter/flutter#189770 (P2, triaged; cdeil confirmed it on 3.47.0 / AGP 9.1.0 using the guide's snippet on a freshly generated plugin), and #190339 is a written, tested fix that rebuilds the report from |
Addresses #636. Applies the official plugin-author migration (docs.flutter.dev → "Migrate to built-in Kotlin" → plugin authors), using the documented variant for plugins that support Flutter versions earlier than 3.44: KGP is applied conditionally only while AGP < 9, and
android.kotlinOptionsmoves to thekotlin { compilerOptions { jvmTarget = ... } }DSL. The buildscript Kotlin classpath is retained because the conditional branch can still apply KGP on older toolchains (kotlin_version 2.2.20 satisfies the compilerOptions DSL floor).Verification (build-verified locally before submitting):
flutter build apk --debugon the example is green on a current pre-release SDK (post-deprecation Gradle semantics, so the new DSL is exercised at configure time) and on Flutter 3.38.3 (older-consumer back-compat).Note: I couldn't capture the warning-disappears transition the 3.44 reporters see — the SDKs I have locally don't emit the KGP deprecation warning even on unmigrated master. This change follows the official migration doc for plugins supporting pre-3.44 Flutter, and the example builds green on both a current pre-release SDK and 3.38.3. Happy to adjust if CI on a newer stable shows anything different.