Skip to content

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

Description

@Nathan98000

Summary

On AGP 9 with android.builtInKotlin=false, workmanager_android cannot be built. Both the current
and the previous release fail, in different ways.

android.builtInKotlin=false is the value Flutter writes by default (flutter/flutter#183910), and
its Android migrator restores it if removed. The AGP 9 handling added after #710 branches on the AGP
major version alone, so it assumes built-in Kotlin is enabled — which, on a default Flutter project,
it is not.

Setting the flag to true is not a general workaround: other plugins still require the legacy path.

Environment

Flutter 3.44.8 (stable, 058e0af2c2)
Dart 3.12.2
AGP 9.0.1
Gradle 9.1.0
KGP 2.3.20 (apply false, per the Flutter template)
Host macOS 26.5.2, Apple Silicon

android/gradle.properties, as generated and maintained by Flutter:

android.useAndroidX=true
android.newDsl=false
android.builtInKotlin=false

Failure 1 — workmanager_android 0.10.4

* What went wrong:
A problem occurred evaluating project ':workmanager_android'.
> Could not find method kotlin() for arguments [...] on project ':workmanager_android'
  of type org.gradle.api.Project.

Build file '.../workmanager_android-0.10.4/android/build.gradle' line: 60

android/build.gradle branches on the AGP major version only:

def agpMajor = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')[0] as int
if (agpMajor < 9) {
    apply plugin: 'kotlin-android'
}
…
if (agpMajor >= 9) {
    kotlin {                       // line 60
        compilerOptions {
            jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_1_8
        }
    }
}

With AGP 9 and built-in Kotlin disabled, neither branch supplies a kotlin extension: KGP is not
applied, and AGP does not contribute one. Evaluation fails.

Failure 2 — workmanager_android 0.9.3

* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> .../GeneratedPluginRegistrant.java:94: error: cannot find symbol
        flutterEngine.getPlugins().add(new dev.fluttercommunity.workmanager.WorkmanagerPlugin());
                                                                           ^
  symbol: class WorkmanagerPlugin

Same if (agpMajor < 9) guard, no kotlin {} block: the script evaluates, but no Kotlin plugin is
applied, the module's Kotlin sources are never compiled, and the plugin class does not exist at
registration. This matches #710, reported there against 0.10.1 / AGP 9.2.1.

Why android.builtInKotlin=true is not a workaround

Plugins that still apply KGP then fail instead. For example, with app_links 7.2.1 present
(a common transitive dependency):

* What went wrong:
An exception occurred applying plugin request [id: 'com.android.library']
> Failed to apply plugin 'com.android.internal.library'.
   > java.lang.IllegalStateException: The 'org.jetbrains.kotlin.android' plugin is no longer
     required for Kotlin support since AGP 9.0.

Removing the org.jetbrains.kotlin.android declaration from settings.gradle.kts does not help.
Deleting the property from gradle.properties does not persist — Flutter's migrator rewrites it:

# This builtInKotlin flag was added automatically by Flutter migrator
android.builtInKotlin=false

Setting it explicitly to true is respected; leaving it absent is not.

Minimal reproduction

  1. flutter create a project with Flutter 3.44.8 (AGP 9.0.1, builtInKotlin=false by default).
  2. Add workmanager: ^0.10.5.
  3. flutter build apk --debugFailure 1.
  4. Change to workmanager: ^0.9.0, flutter build apk --debugFailure 2.
  5. Add any plugin that still applies KGP (e.g. app_links), set android.builtInKotlin=true,
    rebuild → third failure above.

Proposed fix

Condition on both axes rather than on the AGP version alone. flutter_timezone 5.1.0 already does
this:

def agpMajor = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')[0] as int
def builtInKotlinEnabled = /* read android.builtInKotlin */
if (agpMajor < 9 || !builtInKotlinEnabled) {
    apply plugin: 'kotlin-android'
}

Applying the same condition to both the apply plugin guard and the kotlin {} block would make
the module build under either setting, with no behaviour change for projects already migrated.

Confirmation

With workmanager removed and no other change, both platform builds are clean on the configuration
above:

✓ Built build/app/outputs/flutter-apk/app-debug.apk
✓ Built build/ios/iphoneos/Runner.app

iOS is unaffected throughout — workmanager_apple builds correctly once the deployment target is
raised from 13.0 to 14.0.

Related: #710, flutter/flutter#183910.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions