Skip to content

Commit 43cab95

Browse files
committed
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.
1 parent b874f2a commit 43cab95

6 files changed

Lines changed: 33 additions & 48 deletions

File tree

packages/screen_state/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
## 5.0.2
2+
3+
* 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.
4+
* 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)).
5+
* 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`).
6+
* Note: 5.0.1 also raised Android `minSdk` 21 → 24 and `compileSdk` 33 → 36 (undocumented in its changelog).
7+
18
## 5.0.1
29

310
* Fix app not running on Flutter 3.44.X

packages/screen_state/android/build.gradle.kts

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,5 @@
11
group = "dk.cachet.screen_state"
2-
version = "5.0.1"
3-
4-
buildscript {
5-
val kotlinVersion = "2.3.20"
6-
repositories {
7-
google()
8-
mavenCentral()
9-
}
10-
11-
dependencies {
12-
classpath("com.android.tools.build:gradle:9.0.1")
13-
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion")
14-
}
15-
}
2+
version = "5.0.2"
163

174
allprojects {
185
repositories {
@@ -25,6 +12,14 @@ plugins {
2512
id("com.android.library")
2613
}
2714

15+
// AGP 9+ has built-in Kotlin support; on older AGP the Kotlin Gradle plugin
16+
// must be applied explicitly. Version is supplied by the consuming app.
17+
// See https://docs.flutter.dev/release/breaking-changes/migrate-to-built-in-kotlin/for-plugin-authors
18+
val agpMajor = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.substringBefore('.').toInt()
19+
if (agpMajor < 9) {
20+
apply(plugin = "org.jetbrains.kotlin.android")
21+
}
22+
2823
android {
2924
namespace = "dk.cachet.screen_state"
3025

@@ -35,15 +30,6 @@ android {
3530
targetCompatibility = JavaVersion.VERSION_17
3631
}
3732

38-
sourceSets {
39-
getByName("main") {
40-
java.srcDirs("src/main/kotlin")
41-
}
42-
getByName("test") {
43-
java.srcDirs("src/test/kotlin")
44-
}
45-
}
46-
4733
defaultConfig {
4834
minSdk = 24
4935
}
@@ -65,7 +51,7 @@ android {
6551
}
6652
}
6753

68-
kotlin {
54+
project.extensions.configure(org.jetbrains.kotlin.gradle.dsl.KotlinAndroidProjectExtension::class.java) {
6955
compilerOptions {
7056
jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17
7157
}

packages/screen_state/android/src/main/kotlin/dk/cachet/screen_state/ScreenReceiver.java

Lines changed: 0 additions & 21 deletions
This file was deleted.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package dk.cachet.screen_state
2+
3+
import android.content.BroadcastReceiver
4+
import android.content.Context
5+
import android.content.Intent
6+
import io.flutter.plugin.common.EventChannel.EventSink
7+
8+
class ScreenReceiver(private val eventSink: EventSink?) : BroadcastReceiver() {
9+
10+
override fun onReceive(context: Context, intent: Intent) {
11+
eventSink?.success(intent.action)
12+
}
13+
}

packages/screen_state/example/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ publish_to: "none" # Remove this line if you wish to publish to pub.dev
44
version: 5.0.0+1
55

66
environment:
7-
sdk: ^3.12.2
7+
sdk: ^3.10.0
88
flutter: ">=3.6.0"
99

1010
dependencies:

packages/screen_state/pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
name: screen_state
22
description: A plugin for reporting screen events while the flutter application is running in background. Works for Android and iOS only.
3-
version: 5.0.1
3+
version: 5.0.2
44
homepage: https://github.com/carp-dk/flutter-plugins/tree/master/packages/screen_state
55

66
environment:
7-
sdk: ^3.12.2
7+
sdk: ^3.10.0
88
flutter: ">=3.3.0"
99

1010
dependencies:

0 commit comments

Comments
 (0)