Skip to content

fix(network_info_plus): apply KGP unless built-in Kotlin is enabled - #3948

Open
4akloon wants to merge 1 commit into
fluttercommunity:mainfrom
4akloon:fix/network_info_plus-built-in-kotlin-guard
Open

fix(network_info_plus): apply KGP unless built-in Kotlin is enabled#3948
4akloon wants to merge 1 commit into
fluttercommunity:mainfrom
4akloon:fix/network_info_plus-built-in-kotlin-guard

Conversation

@4akloon

@4akloon 4akloon commented Jul 31, 2026

Copy link
Copy Markdown

Description

network_info_plus's Android build script decided whether to apply the Kotlin Gradle Plugin (KGP) from the AGP major version alone:

if (agpMajor < 9) {
    apply(plugin = "org.jetbrains.kotlin.android")
}

That assumes AGP 9 always means built-in Kotlin is active. AGP 9 enables built-in Kotlin only when android.builtInKotlin is not explicitly false — and android.builtInKotlin=false is exactly what flutter create writes into every new app's android/gradle.properties, and what this repository's example apps set.

So on AGP 9 + android.builtInKotlin=false the 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:

Extension of type 'KotlinAndroidProjectExtension' does not exist.

This is not visible today only because Flutter's FlutterPluginUtils.kgpRegexKotlin matches plugins { } blocks but not the imperative apply(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:

// AGP 9 provides Kotlin support natively unless the consuming app opts out with
// android.builtInKotlin=false, which is what `flutter create` writes by default.
val builtInKotlinEnabled =
    agpMajor >= 9 &&
        (providers.gradleProperty("android.builtInKotlin").orNull?.toBoolean() ?: true)

if (!builtInKotlinEnabled) {
    apply(plugin = "org.jetbrains.kotlin.android")
}

The KotlinAndroidProjectExtension block 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 >= 9 is false, so KGP is applied exactly as before.

Full mechanism, AGP bytecode evidence and reproduction steps are in #3944.

Verification

Scenario Result
AGP 9.1.0 / Kotlin 2.4.0 / Gradle 9.3.1, builtInKotlin=false, with Flutter's fallback regex patched out, before fix Fails with KotlinAndroidProjectExtension does not exist
Same, after fix flutter build apk --debug succeeds
AGP 9, builtInKotlin=true Succeeds; KGP correctly not applied
Stock AGP 8.12.1 (current pin) Succeeds

melos run analyze and melos run test:unit_all both pass.

Related Issues

Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I titled the PR using Conventional Commits.
  • I did not modify the CHANGELOG.md nor the plugin version in pubspec.yaml files.
  • All existing and new tests are passing.
  • The analyzer (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?

  • Yes, this is a breaking change (please indicate that with a ! in the title as explained in Conventional Commits).
  • No, this is not a breaking change.

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>
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.

1 participant