From 8b19e0ac375271a7191a1ac300f8613c255eec1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20P=C3=A9tursson?= Date: Fri, 31 Jul 2026 13:40:38 -0700 Subject: [PATCH] feat(android): migrate to built-in Kotlin Closes #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. --- android/build.gradle | 25 ++++++------------------- pubspec.yaml | 6 ++++-- 2 files changed, 10 insertions(+), 21 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index 645f7b9..ea54ef8 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -1,19 +1,6 @@ group 'uk.orth.push' version '1.0-SNAPSHOT' -buildscript { - ext.kotlin_version = '2.1.0' - repositories { - google() - mavenCentral() - } - - dependencies { - classpath 'com.android.tools.build:gradle:8.7.3' - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" - } -} - rootProject.allprojects { repositories { google() @@ -22,7 +9,6 @@ rootProject.allprojects { } apply plugin: 'com.android.library' -apply plugin: 'kotlin-android' android { namespace = "uk.orth.push" @@ -36,10 +22,6 @@ android { targetCompatibility JavaVersion.VERSION_1_8 } - kotlinOptions { - jvmTarget = '1.8' - } - sourceSets { main.java.srcDirs += 'src/main/kotlin' } @@ -49,8 +31,13 @@ android { } } +kotlin { + compilerOptions { + jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_1_8 + } +} + dependencies { - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" implementation "com.google.firebase:firebase-messaging:24.1.0" // Add localbroadcastmanager because firebase-messaging 24+ doesn't include it. // Warning: localbroadcastmanager is deprecated. We still use it because overriding FirebaseMessagingService diff --git a/pubspec.yaml b/pubspec.yaml index e9cab12..99e3d2e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -6,8 +6,10 @@ issue_tracker: https://github.com/ben-xD/push/issues homepage: https://tlduck.com/ environment: - sdk: ">=2.12.0 <4.0.0" - flutter: ">=1.20.0" + # Built-in Kotlin support for plugins landed in Flutter 3.44.0. See + # https://docs.flutter.dev/release/breaking-changes/migrate-to-built-in-kotlin/for-plugin-authors + sdk: ">=3.12.0 <4.0.0" + flutter: ">=3.44.0" dependencies: flutter: