Skip to content

Add support for AGP9#405

Merged
gdelataillade merged 7 commits into
gdelataillade:mainfrom
jmietzITZ:main
Jul 11, 2026
Merged

Add support for AGP9#405
gdelataillade merged 7 commits into
gdelataillade:mainfrom
jmietzITZ:main

Conversation

@jmietzITZ

@jmietzITZ jmietzITZ commented Jun 26, 2026

Copy link
Copy Markdown
Contributor
  • bump compileSdk to 35 (a dependency already requires it)
  • add support for AGP9 with and without builtin kotlin support

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

@gdelataillade gdelataillade left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ✅

  • :alarm compiles on AGP 9 with builtInKotlin=false (the kotlin-android branch) — BUILD SUCCESSFUL.
  • kotlinx-serialization works under built-in Kotlin without kotlin-android — I reproduced the exact gradle setup in an isolated AGP 9 library; .serializer() and Json.encodeToString resolve and compile. This was my biggest worry (it would otherwise have been a silent runtime SerializationException), so good to have it confirmed.
  • The agpMajor < 9 || !builtInKotlin logic and the .orElse(true) default correctly match AGP 9's behavior (built-in Kotlin on by default, bundled KGP 2.2.10). Removing the src/main/kotlin sourceSet 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.gradle still pins classpath '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 want 28.2.13676358).
  • help/INSTALL-ANDROID.md still references compileSdkVersion 34 and applying org.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. 👍

@Adityapanther

Adityapanther commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

I am facing this issue, when would you fix it ?

@jmietzITZ

Copy link
Copy Markdown
Contributor Author

thanks for the feedback, will incorporate the changes probably later today

@Adityapanther

Copy link
Copy Markdown
Contributor

any update ?

@gdelataillade

Copy link
Copy Markdown
Owner

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 build

This commit doesn't touch example/android/app/build.gradle, so kotlinOptions { jvmTarget = '17' } is still missing. Rebuilding gives the same failure as before:

Inconsistent JVM-target compatibility detected for tasks
'compileDebugJavaWithJavac' (17) and 'compileDebugKotlin' (21).  →  BUILD FAILED

It's actually now locked in more explicitly: example/android/gradle.properties was updated to commit android.builtInKotlin=false / android.newDsl=false — which is the exact configuration that hits this failure. Re-adding the kotlinOptions block (as suggested in my first review) still fixes it.

🔴 New: CI (flutter analyze) will fail

The very_good_analysis: ^7.0.0 → ^10.3.0 bump in pubspec.yaml introduces two new discarded_futures lints in files this PR doesn't otherwise touch:

  • lib/service/alarm_storage.dart:114
  • lib/src/platform_timers.dart:113

Verified directly:

  • main (very_good_analysis 7.0.0): flutter analyzeNo issues found! (exit 0)
  • this branch (very_good_analysis 10.3.0): flutter analyze → 2 issues (exit 1)

Since flutter analyze is the only job in .github/workflows/main.yml, this PR will fail CI as-is.

🟠 Worth double-checking: pubspec.yaml SDK constraint change

- sdk: ">=3.0.0 <4.0.0"
+ sdk: ^3.8.0

This raises the minimum Dart SDK for every consuming app to 3.8.0 — looks like incidental fallout from a pub/template refresh rather than something needed for AGP 9 support. If intentional it should get a CHANGELOG callout (it's a breaking change for anyone below 3.8), otherwise worth reverting to keep this PR scoped to the AGP 9 migration. Same question for the json_annotation: ^4.9.0 → ^4.12.0 bump (a shipped dependency) and the pigeon 25→27 dev bump.

✅ Addressed since last review

  • CHANGELOG entry and 5.6.0 version bump — thanks for adding these.

To get this mergeable: re-add the example's jvmTarget, and either revert very_good_analysis to ^7.0.0 or fix the two discarded_futures call sites so flutter analyze is clean again. Happy to take another pass as soon as those land.

@jmietzITZ

Copy link
Copy Markdown
Contributor Author

ran into some issues, there is some stuff to clean up for AGP9 :D
The example app probably still needs to turn builtin kotlin support off, as some other dependencies dont completely support it yet.
Also upgrading the kotlin and some dependency versions introduced some breaking changes which I'm working on fixing.

gdelataillade and others added 3 commits July 11, 2026 12:06
…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>
@gdelataillade

Copy link
Copy Markdown
Owner

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 (maintainerCanModify made that easy — hope that's alright):

  1. Fixed the example build. Re-added kotlinOptions { jvmTarget = '17' }, guarded by the same AGP/built-in-Kotlin conditional as the plugin, so it's correct whether or not built-in Kotlin is active. Also switched ndkVersion to flutter.ndkVersion so it tracks the SDK. This clears the Inconsistent JVM-target compatibility (17 vs 21) blocker.
  2. Reverted the unrelated bumps so the PR stays scoped to AGP 9: the sdk/flutter constraints, json_annotation, pigeon (generated code is still v25.5.0, so no regen needed), and very_good_analysis (10.x added two discarded_futures lints that broke flutter analyze). Version stays 5.6.0.
  3. Added a build-android CI job (the example was never built in CI before) and refreshed the docs/changelog.

Validation

Built and compiled locally on Flutter 3.44.4 / JDK 17:

Scenario Result
Example APK — AGP 9.0.1 / Gradle 9.1 (built-in Kotlin) ✅ builds
:alarm — AGP 8.9.1 / Gradle 8.11.1 / KGP 2.1.0 ✅ compiles
:alarm — AGP 8.9.1 / KGP 2.0.0 (floor) ✅ compiles
flutter analyze / flutter pub publish --dry-run ✅ clean

The AGP 8 legs confirm the biggest risk of the Kotlin bump (2.1.0 → 2.2.10): the kotlinx-serialization compiler subplugin still compiles the plugin's @Serializable models against apps on KGP 2.0.0/2.1.0 — no metadata-version errors. Documented minimum KGP is now 2.0.0 (Flutter 3.44+ already enforces this).

One expected non-issue

Flutter still lists alarm under "plugins that apply Kotlin Gradle Plugin (KGP)…" — its detector is a regex on the (conditional) apply plugin line. There's no KGP-free way to use kotlinx-serialization today, and every current consumer takes the working builtInKotlin=false path, so this is cosmetic and unchanged from released versions. Flagging so nobody files it as a regression.

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>
@gdelataillade
gdelataillade merged commit 63e1ce9 into gdelataillade:main Jul 11, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants