fix(device_info_plus): apply KGP unless built-in Kotlin is enabled - #3947
Open
4akloon wants to merge 1 commit into
Open
fix(device_info_plus): apply KGP unless built-in Kotlin is enabled#39474akloon wants to merge 1 commit into
4akloon wants to merge 1 commit into
Conversation
The guard assumed AGP 9 always means built-in Kotlin is active. AGP enables built-in Kotlin only when android.builtInKotlin is not explicitly false, and `flutter create` writes android.builtInKotlin=false into every new app. On AGP 9 with android.builtInKotlin=false, the plugin skipped KGP and AGP provided no Kotlin either, so nothing compiled the plugin's Kotlin sources and configuration failed at the KotlinAndroidProjectExtension lookup. This was masked only because Flutter's kgpRegexKotlin does not match the imperative apply(plugin = "...") form, so Flutter applied KGP as a fallback on the plugin's behalf. Guard on the same condition AGP itself uses: built-in Kotlin is on when AGP >= 9 and android.builtInKotlin is not explicitly false. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.
Description
device_info_plus's Android build script decided whether to apply the Kotlin Gradle Plugin (KGP) from the AGP major version alone:That assumes AGP 9 always means built-in Kotlin is active. AGP 9 enables built-in Kotlin only when
android.builtInKotlinis not explicitlyfalse— andandroid.builtInKotlin=falseis exactly whatflutter createwrites into every new app'sandroid/gradle.properties, and what this repository's example apps set.So on AGP 9 +
android.builtInKotlin=falsethe plugin skipped KGP and AGP provided no Kotlin either. Nothing compiled the plugin's Kotlin sources, and configuration failed a few lines below at the unconditional extension lookup:This is not visible today only because Flutter's
FlutterPluginUtils.kgpRegexKotlinmatchesplugins { }blocks but not the imperativeapply(plugin = "…")form used here, so Flutter does not see the declaration and applies KGP itself — accidentally papering over the broken guard. Flutter already warns that this fallback is going away.This PR guards on the same condition AGP itself uses:
The
KotlinAndroidProjectExtensionblock below is unchanged — AGP 9's built-in Kotlin registers that extension, so it resolves under both branches. On AGP 8 behaviour is provably identical to today:agpMajor >= 9is false, so KGP is applied exactly as before.Full mechanism, AGP bytecode evidence and reproduction steps are in #3944.
Verification
builtInKotlin=false, with Flutter's fallback regex patched out, before fixKotlinAndroidProjectExtension does not existflutter build apk --debugsucceedsbuiltInKotlin=truemelos run analyzeandmelos run test:unit_allboth pass.Related Issues
Checklist
CHANGELOG.mdnor the plugin version inpubspec.yamlfiles.flutter analyze) does not report any problems on my PR.Breaking Change
Does your PR require plugin users to manually update their apps to accommodate your change?
!in the title as explained in Conventional Commits).