Repository navigation
fix: avoid false KGP warning on AGP 9 builds - #732
Conversation
posthog-flutter Compliance ReportDate: 2026-11-18 07:06:58 UTC ✅ All Tests Passed!45/45 tests passed Capture Tests✅ 29/29 tests passed View Details
Feature_Flags Tests✅ 16/16 tests passed View Details
|
|
Yep, that's covered. The That's the first row of the matrix in the description: Flutter 3.27.4 + AGP 8.11.1 builds on both |
turnipdabeets
left a comment
There was a problem hiding this comment.
LGTM. Checked FlutterPluginUtils.kt at 3.44.8 / 3.47 / 3.50 / master: the lib/KGP regexes only feed detectApplyingKotlinGradlePlugin, so hiding com.android.library just skips the warning and the 3.44-3.46 forced KGP apply. Nit (non-blocking): a CI grep for apply plugin: in this file would stop it regressing.
|
Good call, added it in 00e2b28. CI now fails if It's a bit stricter than Flutter's regex (any plugin ID, not just AGP/KGP), since the file shouldn't use either form anyway. |
💡 Motivation and Context
Fixes #731
Flutter 3.44+ decides whether a plugin applies KGP by regex over the build script text (
kgpRegexGroovy/libPluginRegexGroovyinFlutterPluginUtils.kt), not by what actually ran. Ourandroid/build.gradlehasapply plugin: 'kotlin-android'in two branches that don't run on AGP 9 with built-in Kotlin, so every AGP 9 build printed the "plugins that apply Kotlin Gradle Plugin (KGP): posthog_flutter" warning.Swapping only the two
kotlin-androidlines topluginManager.apply(...)isn't enough. On Flutter 3.44 to 3.46, when the regex findscom.android.librarybut no KGP, Flutter force-applieskotlin-androidwith no built-in Kotlin check (the guard landed in 3.47 via flutter/flutter#188543), and AGP 9 then fails with "The 'org.jetbrains.kotlin.android' plugin is no longer required".So this applies
com.android.librarythroughpluginManagertoo. Flutter then skips our module entirely (if (!hasAppPlugin && !hasLibPlugin) return), and our script keeps applying KGP itself only when it's needed. As far as I can tell Flutter uses the library regex for nothing else (I checked 3.44.8, 3.50.0 and master).The
!builtInKotlinbranch stays: Flutter 3.27 to 3.43 (our floor is 3.27.0) doesn't auto-apply KGP.💚 How did you test it?
I built a minimal probe app (
flutter create, depending only onposthog_fluttervia path) withflutter build apk --debug. "builds" means the build passed and the plugin's Kotlin classes compiled (same class count formainand this branch in every row).mainAlso:
com.android.libraryone.cd example && flutter build apk --debugpasses.Not tested: Flutter 3.28 to 3.43 and 3.45 to 3.49 (code read only). The repo's
example/app can't exercise built-in Kotlin on, becauseflutter_plugin_android_lifecycle2.0.35 applies KGP itself.📝 Checklist
If releasing new changes
pnpm changesetto generate a changeset file🤖 Agent context
DRI: @ioannisj
Autonomy: Human-driven (agent-assisted)