Skip to content

fix(android): avoid Flutter 3.44+ KGP warning and support AGP 9 (#492)#493

Merged
DennisAlund merged 4 commits into
mainfrom
fix/kgp-agp9-builtin-kotlin
Jun 18, 2026
Merged

fix(android): avoid Flutter 3.44+ KGP warning and support AGP 9 (#492)#493
DennisAlund merged 4 commits into
mainfrom
fix/kgp-agp9-builtin-kotlin

Conversation

@DennisAlund

@DennisAlund DennisAlund commented Jun 18, 2026

Copy link
Copy Markdown
Member

Fixes #492.

Problem

On Flutter 3.44+, an app depending on this plugin gets:

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

Flutter detects this with a static text scan of each plugin's android/build.gradle (detectApplyingKotlinGradlePlugin / kgpRegexGroovy in FlutterPluginUtils.kt). The scan matches only the DSL forms — apply plugin: "kotlin-android" and plugins { 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 surrounding if and matches the literal apply 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:

def agpMajor = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')[0] as int
if (agpMajor < 9) {
    project.pluginManager.apply("kotlin-android")
}

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 the kotlin { compilerOptions { jvmTarget } } DSL, and the redundant KGP buildscript classpath is dropped (the consuming app's settings.gradle provides KGP). This supersedes the AGP-9 / android.builtInKotlin guard 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.0 and hasn't migrated. This fix resolves the warning and AGP-9 safety while keeping flutter: ">=3.38.0" unchanged.

Notes / trade-offs

  • Imperative apply is sanctioned, not a hack: it's the same imperative apply the official KTS backwards-compat guide uses (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.
  • The example app is intentionally unchanged. It still 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's build.gradle.
  • The full Android Gradle build is exercised by CI.

🤖 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 both pr_acceptance.yml and build_deploy.yml via uses:. 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:

Cell Flutter AGP Gates? Exercises
floor 3.38.0 8.x agpMajor < 9 path on the minimum SDK
stable latest 8.x current toolchain (where #492 reproduced)
AGP 9 latest 9.1.x ⚠️ continue-on-error agpMajor >= 9 / Built-in Kotlin branch

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

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>
Copilot AI review requested due to automatic review settings June 18, 2026 06:38

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 newer kotlin { 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.yaml and ios/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.

Comment thread android/build.gradle
Comment thread android/build.gradle
DennisAlund and others added 3 commits June 18, 2026 14:49
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>
@DennisAlund DennisAlund merged commit ae509c8 into main Jun 18, 2026
5 checks passed
@DennisAlund DennisAlund deleted the fix/kgp-agp9-builtin-kotlin branch June 18, 2026 07:13
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.

[Bug]: Migrate Plugin to Built-in Kotlin to prevent future build failures

2 participants