Skip to content

fix(android): Avoid KGP warning on AGP 8.x with built-in Kotlin - #120

Merged
spydon merged 1 commit into
mainfrom
fix/kgp-warning-agp8
Jul 7, 2026
Merged

fix(android): Avoid KGP warning on AGP 8.x with built-in Kotlin#120
spydon merged 1 commit into
mainfrom
fix/kgp-warning-agp8

Conversation

@spydon

@spydon spydon commented Jul 6, 2026

Copy link
Copy Markdown
Member

Problem

Follow-up to #115. That change gated the Kotlin Gradle Plugin (KGP) behind an AGP version check:

if (agpMajor < 9) {
    apply plugin: 'kotlin-android'
}

The reasoning was sound, but Flutter's tooling does not detect KGP usage by evaluating this condition at runtime. In FlutterPluginUtils.detectApplyingKotlinGradlePlugin, Flutter scans each plugin's build.gradle text with a regex (it does this deliberately, because evaluating plugin state during configuration causes Gradle lifecycle ordering issues). The Groovy regex matches the literal apply plugin: 'kotlin-android' line anchored at line start, regardless of the surrounding if.

As a result, consumers on Flutter's built-in Kotlin (Flutter 3.44+) with AGP 8.x still see:

WARNING: Your app uses the following plugins that apply Kotlin Gradle Plugin (KGP): gamepads_android

The AGP version was the wrong signal: the warning depends on the text present in the build script, not on which branch executes.

Fixes #119

Change

Apply KGP via project.pluginManager.apply('org.jetbrains.kotlin.android') instead of apply plugin: 'kotlin-android'. This applies the exact same plugin, so Kotlin sources still compile on older Flutter / AGP < 9 (which have no built-in Kotlin), but the form is not matched by Flutter's regex, so gamepads_android is no longer flagged. On AGP 9+ the branch is skipped and Flutter provides Kotlin, unchanged.

This mirrors how plus_plugins fixed the same issue in their Kotlin-DSL packages: they moved KGP out of the plugins {} block into a conditional apply(plugin = ...) call that their regex likewise does not match. This is the Groovy equivalent.

Verification

Verified against Flutter's actual detection regexes (from flutter/flutter master): the previous line matched hasKgpPlugin (triggering the warning), the new file does not, while the required com.android.library detection still matches.

No Android toolchain is available in the dev environment, so this is a static verification against Flutter's detection logic rather than a full build run.

Notes

  • CHANGELOG.md left untouched since it is generated from conventional commits via the release tooling.

The AGP 9 fix (#115) gated `apply plugin: 'kotlin-android'` behind an AGP
version check, but Flutter's tooling detects KGP usage by scanning the
plugin's build.gradle text with a regex, not by evaluating the condition
at runtime. The literal `apply plugin: 'kotlin-android'` line still
matches, so consumers on Flutter's built-in Kotlin (Flutter 3.44+) with
AGP 8.x keep seeing the KGP deprecation warning.

Apply KGP via pluginManager instead, which applies the same plugin for
AGP < 9 so Kotlin sources still compile, but is not matched by Flutter's
build script scan.

Fixes #119
@spydon
spydon merged commit 291d43e into main Jul 7, 2026
8 checks passed
@spydon
spydon deleted the fix/kgp-warning-agp8 branch July 7, 2026 15:04
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.

Flutter KGP warning still occurs on AGP 8.x even after app migration

2 participants