Skip to content

fix(package_info_plus): support AGP 9 / built-in Kotlin#3882

Closed
manuel-goester-n41 wants to merge 1 commit into
fluttercommunity:mainfrom
manuel-goester-n41:fix/package-info-plus-built-in-kotlin
Closed

fix(package_info_plus): support AGP 9 / built-in Kotlin#3882
manuel-goester-n41 wants to merge 1 commit into
fluttercommunity:mainfrom
manuel-goester-n41:fix/package-info-plus-built-in-kotlin

Conversation

@manuel-goester-n41

Copy link
Copy Markdown
Contributor

Summary

AGP 9 removes support for applying the Kotlin Gradle Plugin (KGP). package_info_plus's Android module applies kotlin-android directly, so apps that depend on it fail to build under AGP 9, and Flutter 3.44+ already emits a warning:

WARNING: Your app uses the following plugins that apply Kotlin Gradle Plugin (KGP): … package_info_plus
Future versions of Flutter will fail to build if your app uses plugins that apply KGP.

This migrates package_info_plus to Flutter's built-in Kotlin in a backwards-compatible way. Closes #3881.

Changes

  • Conditional KGP application — apply kotlin-android only when built-in Kotlin is not active, i.e. on AGP < 9 or when android.builtInKotlin=false (the Flutter transition default, which Flutter still sets to false even on AGP 9). This keeps the plugin building on both the legacy-KGP and built-in-Kotlin paths.
  • compilerOptions DSL — replace the deprecated kotlinOptions { jvmTarget } block with kotlin { compilerOptions { jvmTarget = … } }, which works under both KGP and built-in Kotlin.
  • Example app — migrated to built-in Kotlin (kotlin-android removed, compilerOptions DSL).

No change to the supported SDK range, compileSdk (already flutter.compileSdkVersion), the Kotlin version (already 2.2.0 — sufficient for built-in Kotlin on AGP 9), or runtime behavior. Build-configuration only; no public API change.

Verification

Built the example app with Flutter 3.44.2 in each relevant configuration:

Toolchain android.builtInKotlin Result
AGP 8.12.1 / Gradle 8.13 false ✅ builds; plugin applies KGP (legacy path)
AGP 9.0.1 / Gradle 9.1.0 false ✅ builds; KGP applied via Flutter's transition shim
AGP 9.0.1 / Gradle 9.1.0 true package_info_plus is KGP-free and configures cleanly under built-in Kotlin

Under built-in Kotlin the plugin no longer appears in Flutter's KGP warning.

Notes

  • The guard reads android.builtInKotlin, so it automatically tracks whatever Kotlin mode the host app is in — no action required from existing consumers.
  • Per the repo's Melos/conventional-commit workflow, no CHANGELOG.md edit is included; the changelog entry is derived from the fix(package_info_plus): … commit.

AGP 9 removes support for applying the Kotlin Gradle Plugin (KGP). The Android
module applies `kotlin-android` directly, so apps that depend on package_info_plus
fail to build under AGP 9, and Flutter 3.44+ already warns about it.

Apply KGP only when built-in Kotlin is inactive (AGP < 9, or
`android.builtInKotlin=false` — the Flutter transition default), and migrate the
deprecated `kotlinOptions` block to the `kotlin { compilerOptions { } }` DSL. The
example app is migrated to built-in Kotlin as well. No change to the SDK range,
compileSdk (uses flutter.compileSdkVersion), Kotlin version (2.2.0), or runtime.

Verified by building the example with Flutter 3.44.2 on AGP 8.12 (KGP applied),
AGP 9.0.1 + Gradle 9.1.0 with builtInKotlin=false (KGP applied via Flutter's
shim) and builtInKotlin=true (package_info_plus is KGP-free and configures
cleanly under built-in Kotlin).

Closes fluttercommunity#3881

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@vbuberen

Copy link
Copy Markdown
Collaborator

Thanks for your contribution, but I will handle this topic myself as there will be conflicting changes after merging #3858

@vbuberen vbuberen closed this Jun 18, 2026
@mdmahendri

mdmahendri commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Thanks for your contribution, but I will handle this topic myself as there will be conflicting changes after merging #3858

@vbuberen Just following up on this. Do you plan to open PR for the built-in Kotlin compatibility changes, or would you like me to go with follow-up PR with the one already merged?

Also, regarding the addition of:

def builtInKotlin = providers.gradleProperty('android.builtInKotlin').map { it.toBoolean() }.orElse(agpMajor >= 9).get()

I was looking into whether that extra logic is actually necessary. It turns out the Flutter team didn't use that workaround in their example app migration (flutter/packages#11806).

This is because the new Flutter already detects a missing KGP declaration and automatically handles the injection under the hood via detectApplyingKotlinGradlePlugin (introduced in flutter/flutter#184227):

if (!hasKgpPlugin) {
    try {
        pluginManager.apply("kotlin-android")
    } ...
}

Given that the SDK handles the fallback automatically, we should be perfectly safe without manually parsing the android.builtInKotlin flag ourselves.

I tested by copying the code from this guide here https://docs.flutter.dev/release/breaking-changes/migrate-to-built-in-kotlin/for-plugin-authors#supporting-flutter-versions-earlier-than-3-44 using local environment and the KGP warning disappear.

@vbuberen

Copy link
Copy Markdown
Collaborator

Do you plan to open PR for the built-in Kotlin compatibility changes, or would you like me to go with follow-up PR with the one already merged?

I will open PRs myself. You already did enough of good contributions recently. And thanks a lot for such detailed descriptions - it is helpful and saves a lot of time.

@mdmahendri

Copy link
Copy Markdown
Contributor

Great, thanks too! I will continue working on removing the Gradle warnings across the remaining packages then.

@evanrich

Copy link
Copy Markdown

this might still be broken. I just tried adding firebase_analytics to my app, and there's a warning from share_plus and package_info_plus about kotlin:

image

@mdmahendri

Copy link
Copy Markdown
Contributor

I just did a quick test using the latest releases of package_info_plus 10.2.0 and share_plus 13.2.0. Both worked perfectly; running flutter build appbundle did not produce any warnings from either package.

Maybe you can open a new issue with step-by-step instructions using the provided example app. This will help demonstrate reproducibility and ensure the issue isn't isolated to your specific project configuration.

@vbuberen

vbuberen commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator

@evanrich The change follows the official documentation to support apps pre-3.44.x Flutter and I tend to trust the documentation more than whatever LLM threw out on the screenshot. As suggested by another person above - open a proper bug report with steps to reproduce if there is any actual bug.

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.

[package_info_plus] Migrate to Built-in Kotlin (AGP 9 support)

4 participants