Skip to content

fix(android): build with AGP 9 and android.builtInKotlin=false (fixes #722) - #723

Closed
ened wants to merge 1 commit into
mainfrom
fix/agp9-builtin-kotlin
Closed

fix(android): build with AGP 9 and android.builtInKotlin=false (fixes #722)#723
ened wants to merge 1 commit into
mainfrom
fix/agp9-builtin-kotlin

Conversation

@ened

@ened ened commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator

Fixes #722workmanager_android fails to evaluate on AGP 9 when android.builtInKotlin=false (Flutter's default, written by the Android migrator).

Root cause

The AGP 9 handling from #710 branched on the AGP major version alone:

if (agpMajor < 9) { apply plugin: 'kotlin-android' }
...
if (agpMajor >= 9) { kotlin { compilerOptions { ... } } }

AGP 9 only provides the kotlin extension when android.builtInKotlin=true. With the flag false (what flutter create writes on Flutter 3.44+), neither KGP nor built-in Kotlin is active → Could not find method kotlin() at evaluation time. On the previous release (0.9.3) the same guard meant no Kotlin plugin was applied at all and the plugin class was missing at registration.

Fix

Condition on both axes, the same pattern flutter_timezone 5.1.0 ships:

def builtInKotlinEnabled = project.findProperty('android.builtInKotlin')?.toString() == 'true'
if (agpMajor < 9 || !builtInKotlinEnabled) {
    apply plugin: 'kotlin-android'
}
  • AGP < 9: KGP applied as before (unchanged behavior).
  • AGP 9 + builtInKotlin=true: no KGP, built-in Kotlin provides the kotlin extension (unchanged behavior).
  • AGP 9 + builtInKotlin=false (Flutter default): KGP applied → extension present → module builds. This is the case that was broken.

android.builtInKotlin=true remains a valid app-level choice — no plugin change forces it.

Verification (local, exact issue environment)

Standalone Gradle project with AGP 9.0.1 / KGP 2.3.20 / Gradle 9.2 / android.newDsl=false + android.builtInKotlin=false, building the module directly:

Config Before After
AGP 9, builtInKotlin=false Could not find method kotlin() (reproduced, line 60) BUILD SUCCESSFUL, AAR contains 74 classes incl. WorkmanagerPlugin/BackgroundWorker
AGP 9, builtInKotlin=true BUILD SUCCESSFUL, classes present

Regression on the legacy path (example app, AGP 8.11): :workmanager_android:testDebugUnitTest → 50 tests, 0 failures.

One file changed, 7+/7−, no behavior change for already-migrated projects.

The AGP 9 branch assumed built-in Kotlin is enabled. Flutter writes
android.builtInKotlin=false by default (flutter/flutter#183910), so on
AGP 9 the module applied neither KGP nor built-in Kotlin and evaluation
failed with "Could not find method kotlin()".

Condition KGP application on both axes, matching flutter_timezone 5.1.0:
apply KGP when AGP < 9 or built-in Kotlin is disabled.
@ened

ened commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator Author

Superseded by #721 from @EdwynZN — same root cause, same one-file fix, but his guard logic is better: it treats the flag as built-in-Kotlin-active unless explicitly false, which matches AGP 9's actual default (built-in Kotlin on by default). Mine (== 'true') would wrongly apply KGP on AGP 9 when the property is absent.

Full local verification of the equivalent change: AGP 9.0.1 + android.builtInKotlin=false (Flutter default) — reproduced the Could not find method kotlin() failure pre-fix, BUILD SUCCESSFUL + 74 classes in AAR post-fix; builtInKotlin=true mode also green; AGP 8.11 unit tests 50/50. Thank you @EdwynZN 🙏

@ened ened closed this Aug 4, 2026
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.

workmanager_android fails on AGP 9 when android.builtInKotlin=false (Flutter's default)

1 participant