From 43cab959d2a8078f6b40cd75cf99b2efebd54e24 Mon Sep 17 00:00:00 2001 From: Zeroupper Date: Tue, 14 Jul 2026 14:16:39 +0200 Subject: [PATCH] fix(screen_state): restore compatibility with AGP < 9 and Dart 3.12.0 The 5.0.1 release regenerated the Android build script from the Flutter 3.44 plugin template, which pins AGP 9.0.1/Kotlin 2.3.20 on the buildscript classpath and assumes AGP 9 built-in Kotlin. This broke the Android build for every consuming app on AGP 8.x. - Apply the Kotlin Gradle plugin conditionally (AGP < 9) per the Flutter built-in Kotlin migration guide, and drop the pinned buildscript toolchain so the consuming app supplies it. - Relax the Dart SDK lower bound from ^3.12.2 to >=3.12.0; the patch-level pin was a template stamp and blocked Flutter 3.44.0. - Convert ScreenReceiver.java (living in src/main/kotlin) to Kotlin. It was only compiled thanks to a sourceSets override; without it apps crash with NoClassDefFoundError at runtime. Verified: clean debug builds and dex contents on Flutter 3.38.1 (AGP 8.11) and Flutter 3.44.0 (AGP 9.0.1) host apps. --- packages/screen_state/CHANGELOG.md | 7 ++++ .../screen_state/android/build.gradle.kts | 34 ++++++------------- .../cachet/screen_state/ScreenReceiver.java | 21 ------------ .../dk/cachet/screen_state/ScreenReceiver.kt | 13 +++++++ packages/screen_state/example/pubspec.yaml | 2 +- packages/screen_state/pubspec.yaml | 4 +-- 6 files changed, 33 insertions(+), 48 deletions(-) delete mode 100644 packages/screen_state/android/src/main/kotlin/dk/cachet/screen_state/ScreenReceiver.java create mode 100644 packages/screen_state/android/src/main/kotlin/dk/cachet/screen_state/ScreenReceiver.kt diff --git a/packages/screen_state/CHANGELOG.md b/packages/screen_state/CHANGELOG.md index f4990152c..95dd4707c 100644 --- a/packages/screen_state/CHANGELOG.md +++ b/packages/screen_state/CHANGELOG.md @@ -1,3 +1,10 @@ +## 5.0.2 + +* Relax Dart SDK lower bound from `^3.12.2` to `>=3.12.0` — the patch-level pin was accidental and blocked apps on Flutter 3.44.0/3.44.1. +* Fix Android build in apps using AGP < 9: apply the Kotlin Gradle plugin conditionally instead of pinning AGP 9.0.1/Kotlin 2.3.20 on the buildscript classpath (see the [built-in Kotlin migration guide](https://docs.flutter.dev/release/breaking-changes/migrate-to-built-in-kotlin/for-plugin-authors)). +* Fix `NoClassDefFoundError: ScreenReceiver` at runtime: `ScreenReceiver.java` lived in the `src/main/kotlin` folder and relied on a `sourceSets` override to be compiled; it is now converted to Kotlin (`ScreenReceiver.kt`). +* Note: 5.0.1 also raised Android `minSdk` 21 → 24 and `compileSdk` 33 → 36 (undocumented in its changelog). + ## 5.0.1 * Fix app not running on Flutter 3.44.X diff --git a/packages/screen_state/android/build.gradle.kts b/packages/screen_state/android/build.gradle.kts index c5eb428e6..5fd950da3 100644 --- a/packages/screen_state/android/build.gradle.kts +++ b/packages/screen_state/android/build.gradle.kts @@ -1,18 +1,5 @@ group = "dk.cachet.screen_state" -version = "5.0.1" - -buildscript { - val kotlinVersion = "2.3.20" - repositories { - google() - mavenCentral() - } - - dependencies { - classpath("com.android.tools.build:gradle:9.0.1") - classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion") - } -} +version = "5.0.2" allprojects { repositories { @@ -25,6 +12,14 @@ plugins { id("com.android.library") } +// AGP 9+ has built-in Kotlin support; on older AGP the Kotlin Gradle plugin +// must be applied explicitly. Version is supplied by the consuming app. +// See https://docs.flutter.dev/release/breaking-changes/migrate-to-built-in-kotlin/for-plugin-authors +val agpMajor = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.substringBefore('.').toInt() +if (agpMajor < 9) { + apply(plugin = "org.jetbrains.kotlin.android") +} + android { namespace = "dk.cachet.screen_state" @@ -35,15 +30,6 @@ android { targetCompatibility = JavaVersion.VERSION_17 } - sourceSets { - getByName("main") { - java.srcDirs("src/main/kotlin") - } - getByName("test") { - java.srcDirs("src/test/kotlin") - } - } - defaultConfig { minSdk = 24 } @@ -65,7 +51,7 @@ android { } } -kotlin { +project.extensions.configure(org.jetbrains.kotlin.gradle.dsl.KotlinAndroidProjectExtension::class.java) { compilerOptions { jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17 } diff --git a/packages/screen_state/android/src/main/kotlin/dk/cachet/screen_state/ScreenReceiver.java b/packages/screen_state/android/src/main/kotlin/dk/cachet/screen_state/ScreenReceiver.java deleted file mode 100644 index 9ad9d2eb6..000000000 --- a/packages/screen_state/android/src/main/kotlin/dk/cachet/screen_state/ScreenReceiver.java +++ /dev/null @@ -1,21 +0,0 @@ -package dk.cachet.screen_state; - -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; -import io.flutter.plugin.common.EventChannel.EventSink; - -public class ScreenReceiver extends BroadcastReceiver { - - private EventSink eventSink; - - public ScreenReceiver(EventSink eventSink) { - this.eventSink = eventSink; - } - - @Override - public void onReceive(Context context, Intent intent) { - String action = intent.getAction(); - eventSink.success(action); - } -} \ No newline at end of file diff --git a/packages/screen_state/android/src/main/kotlin/dk/cachet/screen_state/ScreenReceiver.kt b/packages/screen_state/android/src/main/kotlin/dk/cachet/screen_state/ScreenReceiver.kt new file mode 100644 index 000000000..8becc6455 --- /dev/null +++ b/packages/screen_state/android/src/main/kotlin/dk/cachet/screen_state/ScreenReceiver.kt @@ -0,0 +1,13 @@ +package dk.cachet.screen_state + +import android.content.BroadcastReceiver +import android.content.Context +import android.content.Intent +import io.flutter.plugin.common.EventChannel.EventSink + +class ScreenReceiver(private val eventSink: EventSink?) : BroadcastReceiver() { + + override fun onReceive(context: Context, intent: Intent) { + eventSink?.success(intent.action) + } +} diff --git a/packages/screen_state/example/pubspec.yaml b/packages/screen_state/example/pubspec.yaml index d989a13c6..c01c2a848 100644 --- a/packages/screen_state/example/pubspec.yaml +++ b/packages/screen_state/example/pubspec.yaml @@ -4,7 +4,7 @@ publish_to: "none" # Remove this line if you wish to publish to pub.dev version: 5.0.0+1 environment: - sdk: ^3.12.2 + sdk: ^3.10.0 flutter: ">=3.6.0" dependencies: diff --git a/packages/screen_state/pubspec.yaml b/packages/screen_state/pubspec.yaml index d8e75388c..b247736a9 100644 --- a/packages/screen_state/pubspec.yaml +++ b/packages/screen_state/pubspec.yaml @@ -1,10 +1,10 @@ name: screen_state description: A plugin for reporting screen events while the flutter application is running in background. Works for Android and iOS only. -version: 5.0.1 +version: 5.0.2 homepage: https://github.com/carp-dk/flutter-plugins/tree/master/packages/screen_state environment: - sdk: ^3.12.2 + sdk: ^3.10.0 flutter: ">=3.3.0" dependencies: