feat(android): migrate to built-in Kotlin - #95
Open
kristjan wants to merge 1 commit into
Open
Conversation
Closes uxduck#91. From AGP 9.0, applying the Kotlin Gradle Plugin is no longer supported. Flutter added a temporary shim so apps and plugins can migrate, and will remove it. Any app depending on `push` currently gets the warning: WARNING: Your app uses the following plugins that apply Kotlin Gradle Plugin (KGP): push Follows https://docs.flutter.dev/release/breaking-changes/migrate-to-built-in-kotlin/for-plugin-authors: - drop the `buildscript` block, which pinned AGP 8.7.3 and KGP 2.1.0. The Kotlin plugin and its version now come from the host app's toolchain - drop `apply plugin: 'kotlin-android'` - replace `android { kotlinOptions { jvmTarget } }` with a top-level `kotlin { compilerOptions { jvmTarget } }` block, keeping JVM 1.8 as set in 3.3.3 - drop the explicit `kotlin-stdlib-jdk7` dependency, which is no longer needed and referenced the now-removed `$kotlin_version` Built-in Kotlin support for plugins requires Flutter 3.44.0, so the environment constraints are raised to match. This is the only consumer-visible change. Two stale values in this file are deliberately left alone, because they affect consumers and are separate problems: `minSdkVersion 16`, and the deprecated `androidx.localbroadcastmanager` dependency that the existing comment explains.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #91.
Migrates the Android plugin to Flutter's built-in Kotlin support, following the migration guide for plugin authors.
Why now
From AGP 9.0, applying the Kotlin Gradle Plugin is no longer supported. Flutter added a temporary shim so apps and plugins can migrate, and has said it will remove it. Until then, every app depending on
pushsees this at build time:pub.dev also applies a scoring penalty for this on the package page.
What changed
Only
android/build.gradle, plus the environment constraints inpubspec.yaml.buildscriptblock, which pinned AGP 8.7.3 and KGP 2.1.0. The Kotlin plugin and its version now come from the host app's toolchain, which is the point of the migration — the plugin no longer forces a Kotlin version on its consumers.apply plugin: 'kotlin-android'.android { kotlinOptions { jvmTarget = '1.8' } }with a top-levelkotlin { compilerOptions { jvmTarget = JvmTarget.JVM_1_8 } }. JVM 1.8 is preserved deliberately — 3.3.3 lowered it back to 1.8 on purpose and this PR is not the place to revisit that.kotlin-stdlib-jdk7dependency. It is no longer needed, and it referenced the now-removed$kotlin_version.Built-in Kotlin support for plugins requires Flutter 3.44.0, so
environmentis raised toflutter: ">=3.44.0"/sdk: ">=3.12.0 <4.0.0". This is the only consumer-visible change, and it is unavoidable — the alternative in the guide is conditional Gradle logic to support both AGP <9 and AGP ≥9, which seemed worse than a floor on a Flutter version that is already the stable channel.Deliberately not changed
Two stale values in this file are worth raising but affect consumers, so they are left for a separate decision:
minSdkVersion 16, far below anything Flutter supports today. Happy to raise it in a follow-up if you want.androidx.localbroadcastmanager:localbroadcastmanager:1.1.0, deprecated. The existing comment explains why it is still there, and replacing it is a real piece of work, not a version bump.No changelog entry or version bump here, deliberately: #94 (Swift Package Manager, #90) also bumps the version, and I did not want the two PRs to conflict or to depend on each other. They touch disjoint directories and can merge in either order. Happy to add the changelog entry to whichever lands second, or to leave the release to you.
How this was verified
Flutter 3.44.2 stable, on the plugin's own
example/app.The warning is gone. Before, on
main:After, on this branch:
share_plusis an unrelated dependency of the example app, and the example app applies KGP itself inexample/android/app/build.gradle— both are outside the plugin and outside this PR.The plugin still compiles.
./gradlew :push:assembleReleaseinexample/androidisBUILD SUCCESSFUL, with:push:compileReleaseKotlinsucceeding without KGP applied. The only warnings are the pre-existingLocalBroadcastManagerdeprecations noted above.One caveat, stated plainly:
flutter build apkon the example app does not complete on my machine, because it stops at:app:processReleaseGoogleServices—google-services.jsonis not committed to this repo. That failure is unrelated to this change and reproduces onmain. It happens after the Gradle configuration phase, so the KGP warning comparison above is still valid, and building the:pushmodule directly covers the compile. I have not run the example app on a device.Offer
Same offer as on #94: I maintain an app that depends on
pushand I would be glad to help maintain the package — triage, reviews, or the remaining deprecations. Happy to take as much or as little as is useful.