From 01fedbe128b020b2a35dfb7d383aa63e9d746bf4 Mon Sep 17 00:00:00 2001 From: Sebastian Roth Date: Tue, 4 Aug 2026 06:15:59 +0100 Subject: [PATCH] fix(android): build with AGP 9 and android.builtInKotlin=false (#722) 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. --- workmanager_android/android/build.gradle | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/workmanager_android/android/build.gradle b/workmanager_android/android/build.gradle index d08f1188..4d6144bd 100644 --- a/workmanager_android/android/build.gradle +++ b/workmanager_android/android/build.gradle @@ -10,14 +10,14 @@ rootProject.allprojects { apply plugin: 'com.android.library' -// AGP 9+ ships built-in Kotlin support; older versions need the Kotlin Gradle -// Plugin (KGP) applied explicitly. Do NOT apply KGP on AGP 9+: it is a no-op -// there for library modules (and deprecated), so Kotlin sources only compile -// via AGP's built-in Kotlin (see flutter/flutter#183910 and #710). Apps that -// still set `android.builtInKotlin=false` on AGP 9 must migrate to built-in -// Kotlin — with that flag no Kotlin plugin compiles at all. +// AGP 9+ ships built-in Kotlin support, but only when the app opts in via +// `android.builtInKotlin=true` in gradle.properties. Flutter writes +// `android.builtInKotlin=false` by default (flutter/flutter#183910), so on +// AGP 9 the plugin must apply KGP itself unless built-in Kotlin is enabled. +// AGP < 9 always needs KGP. See #710 and #722. def agpMajor = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')[0] as int -if (agpMajor < 9) { +def builtInKotlinEnabled = project.findProperty('android.builtInKotlin')?.toString() == 'true' +if (agpMajor < 9 || !builtInKotlinEnabled) { apply plugin: 'kotlin-android' }