Skip to content

fix: avoid false KGP warning on AGP 9 builds - #732

Merged
ioannisj merged 2 commits into
mainfrom
fix/731-kgp-detection-safe-plugin-apply
Nov 18, 2026
Merged

ioannisj merged 2 commits into
mainfrom
fix/731-kgp-detection-safe-plugin-apply

Conversation

@ioannisj

Copy link
Copy Markdown
Contributor

💡 Motivation and Context

Fixes #731

Flutter 3.44+ decides whether a plugin applies KGP by regex over the build script text (kgpRegexGroovy / libPluginRegexGroovy in FlutterPluginUtils.kt), not by what actually ran. Our android/build.gradle has apply 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-android lines to pluginManager.apply(...) isn't enough. On Flutter 3.44 to 3.46, when the regex finds com.android.library but no KGP, Flutter force-applies kotlin-android with 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.library through pluginManager too. 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 !builtInKotlin branch 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 on posthog_flutter via path) with flutter build apk --debug. "builds" means the build passed and the plugin's Kotlin classes compiled (same class count for main and this branch in every row).

Flutter AGP builtInKotlin main this PR
3.27.4 8.11.1 n/a builds builds
3.44.8 8.11.1 n/a builds builds
3.44.8 9.0.1 true builds, warns builds, no warning
3.44.8 9.0.1 false builds, warns builds, no warning
3.50.0 9.3.1 (Gradle 9.5.0, Kotlin 2.4.20, the reporter's setup) true builds, warns builds, no warning
3.50.0 9.3.1 false builds, warns builds, no warning

Also:

  • The changed file matches neither Flutter's KGP regex nor the com.android.library one.
  • cd example && flutter build apk --debug passes.

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, because flutter_plugin_android_lifecycle 2.0.35 applies KGP itself.

📝 Checklist

  • All commits are signed (see Commit signing)
  • I reviewed the submitted code.
  • I added tests to verify the changes.
  • I updated the docs if needed.
  • No breaking change or entry added to the changelog.

If releasing new changes

  • Ran pnpm changeset to generate a changeset file

🤖 Agent context

DRI: @ioannisj
Autonomy: Human-driven (agent-assisted)

@ioannisj ioannisj self-assigned this Nov 17, 2026
@ioannisj
ioannisj marked this pull request as ready for review November 17, 2026 13:22
@ioannisj
ioannisj requested a review from a team as a code owner November 17, 2026 13:22
@veria-ai

veria-ai Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

PR overview

No security issues were found in this pull request.

Reviews

@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

posthog-flutter Compliance Report

Date: 2026-11-18 07:06:58 UTC
Duration: 96758ms

✅ All Tests Passed!

45/45 tests passed


Capture Tests

✅ 29/29 tests passed

View Details
Test Status Duration
Format Validation.Event Has Required Fields ✅ 132ms
Format Validation.Event Has Uuid ✅ 115ms
Format Validation.Event Has Lib Properties ✅ 112ms
Format Validation.Distinct Id Is String ✅ 112ms
Format Validation.Token Is Present ✅ 112ms
Format Validation.Custom Properties Preserved ✅ 114ms
Format Validation.Event Has Timestamp ✅ 113ms
Retry Behavior.Retries On 503 ✅ 5326ms
Retry Behavior.Does Not Retry On 400 ✅ 2115ms
Retry Behavior.Does Not Retry On 401 ✅ 2114ms
Retry Behavior.Respects Retry After Header ✅ 8121ms
Retry Behavior.Implements Backoff ✅ 15442ms
Retry Behavior.Retries On 500 ✅ 5222ms
Retry Behavior.Retries On 502 ✅ 5222ms
Retry Behavior.Retries On 504 ✅ 5221ms
Retry Behavior.Max Retries Respected ✅ 15438ms
Deduplication.Generates Unique Uuids ✅ 117ms
Deduplication.Preserves Uuid On Retry ✅ 5221ms
Deduplication.Preserves Uuid And Timestamp On Retry ✅ 10330ms
Deduplication.Preserves Uuid And Timestamp On Batch Retry ✅ 5224ms
Deduplication.No Duplicate Events In Batch ✅ 118ms
Deduplication.Different Events Have Different Uuids ✅ 112ms
Compression.Sends Gzip When Enabled ✅ 113ms
Batch Format.Uses Proper Batch Structure ✅ 111ms
Batch Format.Flush With No Events Sends Nothing ✅ 107ms
Batch Format.Multiple Events Batched Together ✅ 117ms
Error Handling.Does Not Retry On 403 ✅ 2113ms
Error Handling.Does Not Retry On 413 ✅ 2114ms
Error Handling.Retries On 408 ✅ 5221ms

Feature_Flags Tests

✅ 16/16 tests passed

View Details
Test Status Duration
Request Payload.Request With Person Properties Device Id ✅ 10ms
Request Payload.Flags Request Uses V2 Query Param ✅ 7ms
Request Payload.Flags Request Hits Flags Path Not Decide ✅ 7ms
Request Payload.Flags Request Omits Authorization Header ✅ 6ms
Request Payload.Token In Flags Body Matches Init ✅ 7ms
Request Payload.Groups Round Trip ✅ 6ms
Request Payload.Groups Default To Empty Object ✅ 7ms
Request Payload.Person Properties Distinct Id Auto Populated When Caller Omits It ✅ 6ms
Request Payload.Disable Geoip False Propagates As Geoip Disable False ✅ 7ms
Request Payload.Disable Geoip Omitted Defaults To False ✅ 6ms
Request Payload.Flag Keys To Evaluate Contains Only Requested Key ✅ 7ms
Request Lifecycle.No Flags Request On Init Alone ✅ 3ms
Request Lifecycle.No Flags Request On Normal Capture ✅ 109ms
Request Lifecycle.Two Flag Calls Produce Two Remote Requests ✅ 12ms
Request Lifecycle.Mock Response Value Is Returned To Caller ✅ 6ms
Side Effect Events.Get Feature Flag Captures Feature Flag Called Event ✅ 110ms

@marandaneto

marandaneto commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

i am ok fixing the warning
its cosmetics only tho, similar to #390
we need to make sure this works in flutter 3.6 tho

sdk: '>=3.6.0 <4.0.0'
otherwise a warning would be ok if that brings more compatibility

@ioannisj

Copy link
Copy Markdown
Contributor Author

Yep, that's covered. The >=3.6.0 on that line is the Dart SDK floor, and it lines up with Flutter 3.27 (our flutter: '>=3.27.0' floor in posthog_flutter/pubspec.yaml). Flutter 3.27.4 ships Dart 3.6.2.

That's the first row of the matrix in the description: Flutter 3.27.4 + AGP 8.11.1 builds on both main and this branch, with the plugin's Kotlin classes compiled. pluginManager.apply(...) is plain Gradle API, so I don't think anything here depends on the Flutter version.

@turnipdabeets turnipdabeets left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@ioannisj

Copy link
Copy Markdown
Contributor Author

Good call, added it in 00e2b28. CI now fails if posthog_flutter/android/build.gradle gets an apply plugin: line or a plugins {} block back.

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.

@ioannisj
ioannisj enabled auto-merge (squash) November 18, 2026 07:04
@ioannisj
ioannisj merged commit ddaf3ab into main Nov 18, 2026
30 checks passed
@ioannisj
ioannisj deleted the fix/731-kgp-detection-safe-plugin-apply branch November 18, 2026 07:20
@turnipdabeets turnipdabeets mentioned this pull request Nov 20, 2026
12 of 18 tasks
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.

KGP warning on every AGP 9 build: literal apply plugin: 'kotlin-android' in a branch that never runs

3 participants