fix(android): avoid Flutter 3.44+ KGP warning and support AGP 9 (#492)#493
Merged
Conversation
Apply the Kotlin Gradle Plugin only on AGP < 9, using the imperative
`project.pluginManager.apply("kotlin-android")` form that Flutter's
static KGP scan does not flag; on AGP 9 Flutter's Built-in Kotlin
supplies it. Replace `kotlinOptions` with the `kotlin.compilerOptions`
DSL and supersede the AGP-9 guard from 0.27.1-0.27.2. No change to the
minimum Flutter SDK (>=3.38.0). Add a regression test.
Fixes #492
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the plugin’s Android Gradle configuration to stop triggering Flutter 3.44+ “plugin applies Kotlin Gradle Plugin (KGP)” warnings and to align with Flutter’s Built-in Kotlin direction, while shipping the change as a patch release (0.30.1).
Changes:
- Android: switch KGP application to an imperative
pluginManager.apply(...)path (instead of DSL forms) and move JVM target configuration to the newerkotlin { compilerOptions { ... } }DSL. - Tests: add a regression test that fails if DSL-form KGP application strings are reintroduced into
android/build.gradle. - Release bookkeeping: bump versions in
pubspec.yamlandios/facebook_app_events.podspec, and add a 0.30.1 changelog entry.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
android/build.gradle |
Changes how/when KGP is applied and updates Kotlin compiler options configuration. |
test/android_build_gradle_test.dart |
Adds a regression test preventing reintroduction of Flutter-detected DSL KGP apply patterns. |
pubspec.yaml |
Bumps package version to 0.30.1. |
ios/facebook_app_events.podspec |
Keeps CocoaPods spec version in sync with pubspec (0.30.1). |
CHANGELOG.md |
Documents the 0.30.1 Android change and links to issue #492. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Move the duplicated build confirmation (Android example build + dart tests, iOS example build) into a reusable workflow (`workflow_call`). `pr_acceptance.yml` and `build_deploy.yml` now call it via `uses:`, so the steps live in one place and can't drift; iOS is opt-in (off for PRs, on for release). Add a bounded Android matrix anchored on support endpoints / behavioral breakpoints, not the version cross-product: - Flutter 3.38 floor — exercises the plugin's `agpMajor < 9` path on the minimum supported SDK. - Flutter stable — current default toolchain (where #492 reproduced). - Flutter stable + AGP 9 (continue-on-error) — exercises the `agpMajor >= 9` / Built-in Kotlin branch; allowed to fail until the AGP 9 toolchain stabilises. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Extract the platform-agnostic dart tests (MethodChannel-mocked) into a single `test` job instead of repeating them in every Android matrix cell, and gate the platform builds on it (`needs: [test]`) so the slow/expensive builds (especially macOS iOS) don't run when the Dart layer is broken. The iOS job no longer re-runs the dart tests. Also bump the experimental AGP 9 cell's Gradle to 9.3.1 (AGP 9.1.1's minimum) — the prior 9.1.0 failed the AGP version check, unrelated to the plugin's >=9 branch. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Drop the `include-ios` workflow_call input and run the iOS example build unconditionally, so PRs get the same Android-matrix + iOS verification as the release pipeline. Both callers now invoke build-verify.yml with no parameters. Co-Authored-By: Claude Opus 4.8 (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.
Fixes #492.
Problem
On Flutter 3.44+, an app depending on this plugin gets:
Flutter detects this with a static text scan of each plugin's
android/build.gradle(detectApplyingKotlinGradlePlugin/kgpRegexGroovyinFlutterPluginUtils.kt). The scan matches only the DSL forms —apply plugin: "kotlin-android"andplugins { id "kotlin-android" }. The previous AGP-9 conditional guard (0.27.1–0.27.2) did not silence the warning, because the scan ignores the surroundingifand matches the literalapply plugin:text regardless. The hard failure arrives with AGP 9, which removed support for plugins applying KGP.Fix
Apply KGP only on AGP < 9, via the imperative form Flutter's scan does not flag:
On AGP 9 (and Flutter ≥ 3.44 generally), Flutter's Built-in Kotlin supplies KGP, so the plugin doesn't apply it.
kotlinOptions { jvmTarget }is replaced by thekotlin { compilerOptions { jvmTarget } }DSL, and the redundant KGP buildscript classpath is dropped (the consuming app'ssettings.gradleprovides KGP). This supersedes the AGP-9 /android.builtInKotlinguard from 0.27.1–0.27.2.Why not bump the minimum Flutter SDK to 3.44?
The official guide's primary path bumps the plugin to
flutter: ">=3.44.0". We deliberately did not — that would be a second consecutive min-SDK raise (0.29.0 just moved to 3.38), forcing consumers onto a stable that's days old. For comparison,flutter_facebook_auth(7.1.7) is still at>=3.38.0and hasn't migrated. This fix resolves the warning and AGP-9 safety while keepingflutter: ">=3.38.0"unchanged.Notes / trade-offs
apply(plugin = ...)), which the Kotlin scan also doesn't match. The (low) risk is that a future Flutter could extend the scan to imperative applies.id "kotlin-android"so it builds on Flutter 3.38. Building the example on 3.44+ will show the separate app-level warning about the example app itself — but the plugin no longer appears in the "plugins that apply KGP" list, which is what [Bug]: Migrate Plugin to Built-in Kotlin to prevent future build failures #492 reports.Verification
flutter test— 63/63 pass, including a new regression guard (test/android_build_gradle_test.dart) that fails if a DSL-form KGP apply is reintroduced into the plugin'sbuild.gradle.🤖 Generated with Claude Code
CI (added in this PR)
Per discussion, the build confirmation is now DRY: a reusable workflow (
.github/workflows/build-verify.yml,on: workflow_call) is the single source of truth, called by bothpr_acceptance.ymlandbuild_deploy.ymlviauses:. The previously-duplicated Android build + dart tests (which lived in both files and could drift) are gone. iOS is opt-in — off for PRs (macOS cost), on for the release pipeline.It adds a bounded Android matrix anchored on support endpoints / behavioral breakpoints, not the version cross-product:
agpMajor < 9path on the minimum SDKcontinue-on-erroragpMajor >= 9/ Built-in Kotlin branchThe AGP-9 cell flips AGP→9.1.1 + Gradle→9.1.0 and migrates the example for Built-in Kotlin; it's
continue-on-error(a forward-looking signal, not a gate) until the AGP 9 / Flutter toolchain stabilises.