Skip to content

feat(android): migrate to built-in Kotlin - #95

Open
kristjan wants to merge 1 commit into
uxduck:mainfrom
HahaMoment:builtin-kotlin
Open

feat(android): migrate to built-in Kotlin#95
kristjan wants to merge 1 commit into
uxduck:mainfrom
HahaMoment:builtin-kotlin

Conversation

@kristjan

Copy link
Copy Markdown

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 push sees this at build time:

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

pub.dev also applies a scoring penalty for this on the package page.

What changed

Only android/build.gradle, plus the environment constraints in pubspec.yaml.

  • Removed 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, which is the point of the migration — the plugin no longer forces a Kotlin version on its consumers.
  • Removed apply plugin: 'kotlin-android'.
  • Replaced android { kotlinOptions { jvmTarget = '1.8' } } with a top-level kotlin { 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.
  • Removed the explicit kotlin-stdlib-jdk7 dependency. 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 environment is raised to flutter: ">=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:

WARNING: Your app uses the following plugins that apply Kotlin Gradle Plugin (KGP): push, share_plus

After, on this branch:

WARNING: Your app uses the following plugins that apply Kotlin Gradle Plugin (KGP): share_plus

share_plus is an unrelated dependency of the example app, and the example app applies KGP itself in example/android/app/build.gradle — both are outside the plugin and outside this PR.

The plugin still compiles. ./gradlew :push:assembleRelease in example/android is BUILD SUCCESSFUL, with :push:compileReleaseKotlin succeeding without KGP applied. The only warnings are the pre-existing LocalBroadcastManager deprecations noted above.

One caveat, stated plainly: flutter build apk on the example app does not complete on my machine, because it stops at :app:processReleaseGoogleServicesgoogle-services.json is not committed to this repo. That failure is unrelated to this change and reproduces on main. It happens after the Gradle configuration phase, so the KGP warning comparison above is still valid, and building the :push module 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 push and 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.

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

Migrate Plugin to Built-in Kotlin

1 participant