fix(screen_state): restore compatibility with AGP < 9 and Dart 3.10.0#1301
fix(screen_state): restore compatibility with AGP < 9 and Dart 3.10.0#1301Zeroupper wants to merge 1 commit into
Conversation
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.
|
@Zeroupper can't you update your project's AGP to 9 or higher? soon the < 9 AGP will be deprecated and we have to re-update it again. it would make sense to update your projects AGP. Also why did you remove the buildscript? |
The buildscript {} block is Gradle's old way of saying "here are the jars needed to run this build script" — it downloads the listed plugins (AGP 9.0.1, Kotlin 2.3.20) and puts them on the script's classpath before the script executes. The reason it had to go is where this script actually runs. A Flutter plugin's android/ project is never built by itself — Flutter injects it as a subproject into each consuming app's Gradle build, and the app's settings.gradle.kts already decides which AGP and Kotlin versions the whole build uses. So the block does one of two things, both bad:
The one scenario where a buildscript block earns its keep is a standalone build of the plugin's android/ folder — its own ./gradlew, its own toolchain. That scenario doesn't exist for screen_state: no wrapper, a one-line settings.gradle.kts, no CI job. It's embedded-only, and embedded means the host provides the toolchain. --- That's on why the buildscipt got removed. 2nd part of the problem is that I don't think it's a good idea to be overrestrictive on AGP version. I added conditional AGP support for 8 based on the documentation. My goal was to not overrestrict dart version if there is an option. |
|
The whole issue started from being unable to run CAMS/example with Flutter 3.44.0. |
|
@Zeroupper well then can't you update the cams example to be compatible with the new version? instead of downgrading things it depends on |
I didn't downgrade anything, I only added support for older versions. You can't expect everyone to be on the latest dart sdk version, at least support the version that can still run your dependencies. |
Problem
screen_state 5.0.1 (#regenerated from the Flutter 3.44 plugin template) broke two things for consuming apps:
build.gradle.ktspins AGP 9.0.1/Kotlin 2.3.20 on the buildscript classpath and relies on AGP 9 built-in Kotlin (kotlin {}with no Kotlin plugin applied). Any app whoseandroid/project uses AGP 8.x gets script compilation errors (srcDirs ... deprecated,Unresolved reference: kotlin).^3.12.2blocks Flutter 3.44.0/3.44.1 users. The patch-level pin is a template stamp, not a real requirement.Fix
>=3.12.0 <4.0.0(also in the example app).ScreenReceiver.java→ScreenReceiver.kt. The Java file lived insrc/main/kotlinand was only compiled because of the oldsourceSetsoverride; without that override apps crash at runtime withNoClassDefFoundError: dk.cachet.screen_state.ScreenReceiverwhen the stream is first listened to.Verification
flutter build apk --debugof a consuming app on Flutter 3.38.1 / AGP 8.11.1 and of the bundled example on Flutter 3.44.0 / AGP 9.0.1.dexdumpconfirms class definitions for bothScreenStatePluginandScreenReceiverin both APKs.