Skip to content

Support AGP 9 built-in Kotlin - #367

Open
SLIPPECAT wants to merge 1 commit into
note11g:mainfrom
SLIPPECAT:support-agp9-built-in-kotlin
Open

Support AGP 9 built-in Kotlin#367
SLIPPECAT wants to merge 1 commit into
note11g:mainfrom
SLIPPECAT:support-agp9-built-in-kotlin

Conversation

@SLIPPECAT

Copy link
Copy Markdown

Summary

Android Gradle Plugin 9.0 ships built-in Kotlin support and registers its own kotlin { } extension. Unconditionally applying apply plugin: 'kotlin-android' on top of it now fails with:

Failed to apply plugin 'kotlin-android'.
> ⛔ Failed to apply plugin 'org.jetbrains.kotlin.android'
  The 'org.jetbrains.kotlin.android' plugin is no longer required for Kotlin support since AGP 9.0.

This currently blocks any app that has adopted AGP 9 with built-in Kotlin enabled (the default once on AGP 9, unless the app opts out) from depending on flutter_naver_map. Flutter's own build now flags this plugin explicitly:

WARNING: Your app uses the following plugins that apply Kotlin Gradle Plugin (KGP): ... flutter_naver_map ...
Future versions of Flutter will fail to build if your app uses plugins that apply KGP.

Fix

Per Flutter's Built-in Kotlin migration guide for plugin authors:

  • Only apply 'kotlin-android' when it's actually needed: on AGP < 9, or on AGP 9+ where the consuming app has explicitly opted out via android.builtInKotlin=false in gradle.properties (this is currently Flutter's recommended interim state for most AGP 9 adopters, since much of the plugin ecosystem hasn't migrated yet).
  • Move the jvmTarget configuration out of the deprecated android { kotlinOptions { } } block into the top-level kotlin { compilerOptions { } } block, since that extension is registered in both the classic-plugin and built-in-Kotlin cases.

Testing

Verified against a real Flutter app (AGP 9.0.1, Gradle 9.1.0, android.builtInKotlin=false — today's supported "opt-out" combination) via a local path dependency_override: flutter build appbundle --release succeeds with this change, producing the same output as with the currently published version — no regression for existing users on this combination or on AGP < 9.

The android.builtInKotlin=true path (requires Flutter 3.47+) follows AGP's documented built-in-Kotlin behavior, but I wasn't able to independently build-test it since it needs a newer Flutter SDK than what's available in my test app.

Happy to adjust the approach if you'd prefer a different structure (e.g. matching the pattern used in flutter/packages' first-party plugins).

AGP 9 ships built-in Kotlin support and registers its own `kotlin { }`
extension. Unconditionally applying the classic 'kotlin-android' plugin
on top of it fails ("no longer required for Kotlin support since AGP 9"),
which currently blocks apps that adopt AGP 9 with built-in Kotlin enabled
from depending on this plugin.

Only apply 'kotlin-android' when it's actually needed: on AGP < 9, or on
AGP 9+ where the app has explicitly opted out via
`android.builtInKotlin=false` (Flutter's current recommended interim
state for AGP 9 adopters). Move the jvmTarget configuration to the
top-level `kotlin { compilerOptions { } }` block per Flutter's plugin
migration guide, since that extension is present in both cases.

Verified against a real Flutter app on AGP 9.0.1 / Gradle 9.1.0 with
`android.builtInKotlin=false` (today's supported "opt-out" combination)
— `flutter build appbundle --release` succeeds with this change, with
no change in output versus the current published version. The
`builtInKotlin=true` path (Flutter 3.47+) follows AGP's documented
built-in Kotlin behavior but wasn't independently build-tested since it
requires a newer Flutter SDK than what's available in the test app.

See https://docs.flutter.dev/release/breaking-changes/migrate-to-built-in-kotlin/for-plugin-authors
@SLIPPECAT

Copy link
Copy Markdown
Author

Friendly bump on this — Flutter 3.47.2 (stable) is out now, which is the SDK version needed to actually build-test the android.builtInKotlin=true path mentioned above (the one part I couldn't verify when I opened this PR). I've upgraded my test app to 3.47.2 — happy to run that verification and post the results here if it'd help move this forward. Let me know if there's anything else needed on my end.

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.

1 participant