KGP warning on every AGP 9 build: literal `apply plugin: 'kotlin-android'` in a branch that never runs
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 76/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Domain
- build-system, developer-experience
Research direction
Start with android/build.gradle lines 29–41 and the Flutter warning regex in flutter_tools/gradle/src/main/kotlin/FlutterPluginUtils.kt cited in the report. Check how the conditional apply plugin lines are detected as text, then run the stated Flutter release build with AGP 9 and built-in Kotlin enabled. Done means the build succeeds without the false KGP warning while preserving the AGP 8 path.
Written by the indexing model from the issue text.
Description
Version
5.61.0
Steps to Reproduce
- Flutter app on AGP 9.x with
android.builtInKotlin=trueinandroid/gradle.properties. - Add
posthog_flutter: ^5.61.0. flutter build appbundle --release.
Environment: Flutter 3.50.0 stable (ab2912035e), Dart 3.14.0, AGP 9.3.1, Gradle 9.5.0, Kotlin 2.4.20, JDK 21,
android.builtInKotlin=true, android.newDsl=false.
Expected Result
No KGP warning. posthog_flutter 5.61.0 is already built-in-Kotlin compatible — android/build.gradle:29-41 reads
android.builtInKotlin and does not apply KGP when it is on, so there is nothing for Flutter to warn about.
Actual Result
The build succeeds, but prints on every run:
WARNING: Your app uses the following plugins that apply Kotlin Gradle Plugin (KGP): posthog_flutter
Future versions of Flutter will fail to build if your app uses plugins that apply KGP.
This is a false positive. Flutter detects KGP by regex over the build-script text, not by runtime plugin state
(flutter_tools/gradle/src/main/kotlin/FlutterPluginUtils.kt, kgpRegexGroovy):
^[ \t]*apply[ \t]+plugin[ \t]*:[ \t]*(['"])(?:kotlin-android|org\.jetbrains\.kotlin\.android)\1
android/build.gradle:29-41 contains the literal on two lines, and both match even though neither executes in this
configuration:
def agpMajor = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')[0] as int
if (agpMajor < 9) {
apply plugin: 'kotlin-android' // line 31 — not reached on AGP 9
} else {
def builtInKotlin = providers.gradleProperty('android.builtInKotlin')
.map { it.toBoolean() }
.getOrElse(true)
if (!builtInKotlin) {
apply plugin: 'kotlin-android' // line 39 — false when built-in Kotlin is on
}
}
getSubprojectPluginState() reads the file and regex-matches it; the comment there says text matching was chosen
deliberately over querying plugin state, to avoid Gradle lifecycle/ordering issues (gradle/gradle#36953). So no
conditional structure avoids the match — only not writing the literal.
That the plugin really isn't applying KGP is provable: AGP 9 hard-fails when a library applies kotlin-android while
built-in Kotlin is on —
Failed to apply plugin 'org.jetbrains.kotlin.android'
The 'org.jetbrains.kotlin.android' plugin is no longer required for Kotlin support since AGP 9.0.
I hit exactly that error from a different plugin in the same project and the build stopped outright. With
posthog_flutter it builds fine, so line 39 is provably not executing.
This matters beyond the noise: Flutter says future versions will fail builds using plugins that apply KGP. If that
check becomes an error while still being textual, posthog_flutter will break those builds despite being compatible.
Suggested fix — keep the AGP 8 path but avoid the literal string:
if (agpMajor < 9) {
project.pluginManager.apply('kotlin-android')
}
That does not match the regex. Dropping the AGP < 9 branch once AGP 9 is the floor would also work. Note the
!builtInKotlin branch on line 39 is unreachable in practice: when built-in Kotlin is off, Flutter's own Gradle
plugin applies kotlin-android to plugin subprojects that lack it, so posthog doesn't need to.
- Dominant language
- Dart
- Stars
- 99
- Forks
- 94
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 65
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from PostHog/posthog-flutter
-
dependencies enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
PostHog/posthog-flutter#377 · 3 comments ·
Maintainers usually reply within 1 day
-
enhancement feature/error-tracking
Difficulty 5/5 Over a week Newbie friendliness 28/100
PostHog/posthog-flutter#623 ·
Maintainers usually reply within 1 day
-
Support widgetOpenenhancement
Difficulty 4/5 3-5 days Newbie friendliness 30/100
PostHog/posthog-flutter#596 · 1 comment ·
Maintainers usually reply within 1 day
-
enhancement feature/replay
Difficulty 4/5 3-5 days Newbie friendliness 52/100
PostHog/posthog-flutter#593 · 5 comments ·
Maintainers usually reply within 1 day
-
Session replay: support v2 trigger groups (conditional recording)Possibly taken @marc-merino claimed this 39 days ago. Openenhancement feature/replay
Difficulty 5/5 Over a week Newbie friendliness 35/100
PostHog/posthog-flutter#545 ·
Maintainers usually reply within 1 day
All issues in PostHog/posthog-flutter
Similar issues
-
bug enhancement needs-triage
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
-
bug from-telegram platform:windows
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
hiddify/hiddify-app#2592 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
cogwheel0/conduit#1122 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
bannzai/shoppinglist#779 ·
Maintainers usually reply within 1 day
-
[BUG] JEFIT import fails because # characters are not recognisedPossibly taken A pull request linked to this issue is open or already merged. Openbug
Difficulty 1/5 Under an hour Newbie friendliness 88/100
Maintainers usually reply within 1 day