fix(android): Avoid KGP warning on AGP 8.x with built-in Kotlin - #120
Merged
Conversation
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
erickzanardo
approved these changes
Jul 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Follow-up to #115. That change gated the Kotlin Gradle Plugin (KGP) behind an AGP version check:
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'sbuild.gradletext with a regex (it does this deliberately, because evaluating plugin state during configuration causes Gradle lifecycle ordering issues). The Groovy regex matches the literalapply plugin: 'kotlin-android'line anchored at line start, regardless of the surroundingif.As a result, consumers on Flutter's built-in Kotlin (Flutter 3.44+) with AGP 8.x still see:
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 ofapply 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, sogamepads_androidis no longer flagged. On AGP 9+ the branch is skipped and Flutter provides Kotlin, unchanged.This mirrors how
plus_pluginsfixed the same issue in their Kotlin-DSL packages: they moved KGP out of theplugins {}block into a conditionalapply(plugin = ...)call that their regex likewise does not match. This is the Groovy equivalent.Verification
Verified against Flutter's actual detection regexes (from
flutter/fluttermaster): the previous line matchedhasKgpPlugin(triggering the warning), the new file does not, while the requiredcom.android.librarydetection 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.mdleft untouched since it is generated from conventional commits via the release tooling.