Skip to content

fix(android): Migrate workmanager_android to built-in Kotlin - #744

Closed
kuhyx wants to merge 1 commit into
fluttercommunity:mainfrom
kuhyx:built-in-kotlin
Closed

kuhyx wants to merge 1 commit into
fluttercommunity:mainfrom
kuhyx:built-in-kotlin

Conversation

@kuhyx

@kuhyx kuhyx commented Oct 9, 2026

Copy link
Copy Markdown

Summary

Fixes #743.

workmanager_android still has apply plugin: 'kotlin-android' in its build file, behind the builtInKotlin guard from #721. Flutter detects KGP by running a regex (kgpRegexGroovy) over the build file text, and the regex ignores the surrounding if. As a result:

This PR follows the plugin author guide:

  • workmanager_android/android/build.gradle: removes the guarded apply plugin: 'kotlin-android', the agpMajor/builtInKotlin detection and the agpMajor < 9 kotlinOptions block. The existing top-level kotlin { compilerOptions { jvmTarget = JVM_1_8 } } is now unconditional, so it still matches compileOptions.
  • workmanager_android/pubspec.yaml: raises the minimum to Flutter 3.47.0 / Dart 3.13.0. When built-in Kotlin is not active (AGP < 9, or android.builtInKotlin=false, which is Flutter's default), the Flutter Gradle Plugin applies kotlin-android itself to plugins whose build file doesn't mention it. That is what keeps the workmanager_android fails on AGP 9 when android.builtInKotlin=false (Flutter's default) #722 configuration building without the guard.
    • The guide's floor is 3.44, but on every 3.44.x release that auto-apply ignores android.builtInKotlin. With android.builtInKotlin=true on AGP 9, Flutter 3.44.x applies KGP to the migrated module and the build fails with "The 'org.jetbrains.kotlin.android' plugin is no longer required for Kotlin support since AGP 9.0". The current guarded 0.10.9 builds in that same configuration, so a 3.44 floor would regress those apps. 3.47.0 is the first release that skips the auto-apply when built-in Kotlin is on (isBuiltInKotlinEnabled), and there is no 3.45/3.46 stable.
  • .fvmrc: 3.44.8 → 3.47.7, so CI builds against a version inside the new floor.
  • example/android: Flutter 3.47's build checks reject the example's toolchain, so it is raised to the minimums 3.47.7 accepts:
    • Gradle wrapper 8.13 → 9.3.1 (what flutter create generates on 3.47.7; the floor is 8.14).
    • AGP 8.11.0 → 8.11.1 (the floor).
    • KGP 2.1.0 → 2.3.20 (the floor is 2.2.20; 2.3.20 avoids the "soon unsupported" warning).
  • AGENTS.md: replaces the "must apply kotlin-android … do NOT simplify" note, which this change makes obsolete, with why the module must not mention kotlin-android at all and why the floor is 3.47.

The example app otherwise stays on AGP 8 and applies KGP itself. Migrating it to AGP 9 and built-in Kotlin is a separate step.

Breaking Changes

There are no API changes and apps need no changes.

The minimum supported SDK rises from Flutter 3.38 / Dart 3.5 to Flutter 3.47 / Dart 3.13, for workmanager_android only. Apps on Flutter < 3.47 (including all of 3.44.x) keep resolving workmanager_android 0.10.9 through workmanager's ^0.10.9 constraint, so this can ship as a patch and nobody is left without a working version.

Before:

def agpMajor = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')[0] as int
def builtInKotlin = agpMajor >= 9 &&
    project.findProperty('android.builtInKotlin')?.toString() != 'false'
if (!builtInKotlin) {
    apply plugin: 'kotlin-android'
}

After: no KGP reference. Kotlin is compiled by built-in Kotlin, or by the KGP that Flutter applies.

Testing

Flutter 3.47.7, JDK 21:

  • example: flutter build apk --debug (no skip flags) succeeds against the local packages, using a melos-equivalent pubspec_overrides.yaml. WorkmanagerPlugin is in the APK.
  • cd example/android && ./gradlew :workmanager_android:testDebugUnitTest (now on Gradle 9.3.1): BUILD SUCCESSFUL, 63 tests, 0 failures, 0 errors.
  • A fresh flutter create app (AGP 9.1.0, Gradle 9.3.1, KGP 2.4.0) depending on this branch:
    • Before this change: the warning lists workmanager_android with both android.builtInKotlin=false and =true.
    • With android.builtInKotlin=false: the build succeeds, the warning is gone, and WorkmanagerPlugin is compiled and present in the APK.
    • With android.builtInKotlin=true: the same.
  • Why not 3.44: Flutter 3.44.8, with the AGP 9.0.1 / Gradle 9.1.0 / KGP 2.3.20 template and android.builtInKotlin=true, an app depending on only workmanager_android:
    • 0.10.9 builds.
    • This change, with a 3.44 floor, fails with "The 'org.jetbrains.kotlin.android' plugin is no longer required for Kotlin support since AGP 9.0".
    • With android.builtInKotlin=false, both build on 3.44.8.

Related: flutter/flutter#189770, ABausG/home_widget#461 (same pattern in home_widget)

🤖 Generated with Claude Code

https://claude.ai/code/session_01AcxgxMaQHMSGWzLRpNSkuP

@kuhyx kuhyx closed this Oct 9, 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: guarded apply plugin: 'kotlin-android' is the pattern Flutter says will stop building (flutter/flutter#189770)

1 participant