Add support for AGP9#405
Conversation
gdelataillade
left a comment
There was a problem hiding this comment.
Thanks for tackling this 🙏 — AGP 9 support is overdue and the conditional approach here is the right shape. I built and tested the branch against AGP 9.0.1 / Gradle 9.1 / JDK 17 in both Kotlin configurations before reviewing. Summary: the published plugin (android/build.gradle) is solid and non-regressing, but the PR can't merge as-is because the example app no longer builds under current Flutter.
What I verified ✅
:alarmcompiles on AGP 9 withbuiltInKotlin=false(thekotlin-androidbranch) —BUILD SUCCESSFUL.kotlinx-serializationworks under built-in Kotlin withoutkotlin-android— I reproduced the exact gradle setup in an isolated AGP 9 library;.serializer()andJson.encodeToStringresolve and compile. This was my biggest worry (it would otherwise have been a silent runtimeSerializationException), so good to have it confirmed.- The
agpMajor < 9 || !builtInKotlinlogic and the.orElse(true)default correctly match AGP 9's behavior (built-in Kotlin on by default, bundled KGP 2.2.10). Removing thesrc/main/kotlinsourceSet is safe.
🔴 Blocker: the example app fails to build
flutter build apk on this branch fails with:
Inconsistent JVM-target compatibility detected for tasks
'compileDebugJavaWithJavac' (17) and 'compileDebugKotlin' (21).
Flutter's migrator forces android.builtInKotlin=false, so removing kotlinOptions { jvmTarget = '17' } from example/android/app/build.gradle leaves Kotlin defaulting to JVM 21 against Java 17. Re-adding it fixes the build (verified — ✓ Built app-debug.apk):
kotlinOptions {
jvmTarget = '17'
}Worth mirroring the plugin's conditional guard so it's correct whether or not built-in Kotlin is active.
⚠️ Heads-up: migration is partial (not a blocker)
Because the plugin still applies kotlinx-serialization, Flutter continues to report alarm under "plugins that apply Kotlin Gradle Plugin (KGP) … future versions of Flutter will fail to build." There's no KGP-free way to use serialization today, so this is expected — but it means the full built-in-Kotlin path isn't actually reachable end-to-end via current Flutter yet (forcing builtInKotlin=true NPEs in Flutter's own gradle plugin, and sibling plugins like flutter_fgbg/permission_handler aren't migrated). Every current consumer hits the builtInKotlin=false branch, which works. Just flagging so expectations are clear.
Minor / optional
android/build.gradlestill pinsclasspath 'com.android.tools.build:gradle:8.7.0'— works only because the app's AGP shadows it; a plugin shouldn't pin AGP.- Example still pins
ndkVersion "27.0.12077973"(AGP 9 plugins now want28.2.13676358). help/INSTALL-ANDROID.mdstill referencescompileSdkVersion 34and applyingorg.jetbrains.kotlin.android— outdated for AGP 9.- compileSdk 34 → 35 is fine, but worth a CHANGELOG note since consumers on 34 may get a warning.
Could you re-add the example app's jvmTarget? Once the example builds I'm happy to merge. 👍
|
I am facing this issue, when would you fix it ? |
|
thanks for the feedback, will incorporate the changes probably later today |
|
any update ? |
|
Thanks for the update! I re-tested 1629cef against AGP 9.0.1 / Gradle 9.1 / JDK 17. The original blocker isn't resolved yet, and this commit introduces a new CI failure — flagging both before this goes further. 🔴 Blocker still open: example app doesn't buildThis commit doesn't touch It's actually now locked in more explicitly: 🔴 New: CI (
|
|
ran into some issues, there is some stuff to clean up for AGP9 :D |
…kVersion
The example app removed `kotlinOptions { jvmTarget }` but Flutter's migrator
keeps `android.builtInKotlin=false`, so Kotlin defaulted to JVM 21 against
Java 17 and `flutter build apk` failed with an inconsistent-JVM-target error.
Restore it behind the same AGP/built-in-Kotlin guard the plugin uses, and let
ndkVersion follow the Flutter SDK default instead of a pinned value.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Keep this PR scoped to AGP 9 support. Revert the incidental bumps: - sdk constraint back to ">=3.0.0 <4.0.0" (^3.8.0 would break consumers on Dart < 3.8) - json_annotation back to ^4.9.0 (its 4.12 floor is what forced the sdk bump) - pigeon back to ^25.3.1 (generated code is still v25.5.0; no regen here) - very_good_analysis back to ^7.0.0 (10.x adds discarded_futures lints that break `flutter analyze`) Version stays 5.6.0. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
- Add a build-android CI job that builds the example APK on every PR (ubuntu, JDK 21 so JVM-target mismatches surface, Gradle caching). CI previously only ran `flutter analyze`, so Gradle changes were untested. - INSTALL-ANDROID.md: compileSdk 34 -> 35, Kotlin floor 1.9.0 -> 2.0.0, and a note that AGP 9 apps need no settings-level Kotlin plugin. - Expand the 5.6.0 changelog entry. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
Thanks for getting this to the finish line @jmietzITZ 🙏 — the conditional approach here is exactly right. To wrap it up I pushed three commits to the branch (
ValidationBuilt and compiled locally on Flutter 3.44.4 / JDK 17:
The AGP 8 legs confirm the biggest risk of the Kotlin bump ( One expected non-issueFlutter still lists Once CI is green I'll squash-merge. Thanks again! |
The build-android CI job OOMed in JetifyTransform on Flutter's engine jars with the default -Xmx1536M. Jetifier is unnecessary (all dependencies are AndroidX), so disable it and raise the heap to 4G. Verified: example APK builds on AGP 9.0.1 / Gradle 9.1. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Only tested so far inside my flutter app. It would be great if others could also test this code in their apps to be sure there are no issues!
Relevant Issue: #392