Skip to content

AGP 9 built-in Kotlin: remove unconditional kotlin-android apply #125

Description

@TN19N

Problem

Flutter 3.44 / Android Gradle Plugin 9+ deprecated the standalone Kotlin Gradle Plugin (KGP) in favour of AGP's built-in Kotlin support (android.builtInKotlin=true, the default on AGP 9+).

This plugin currently applies kotlin-android unconditionally in its Android build file, e.g.:

apply plugin: 'kotlin-android'

Apps on AGP 9+ work today because the Flutter tool temporarily adds android.builtInKotlin=false as a compatibility shim (flutter/flutter#181383), but this shim is scheduled for removal before AGP 10. When removed, any plugin still applying kotlin-android unconditionally will break the Android build.

Suggested fix

Guard the apply with an AGP version check, the same pattern used by device_info_plus, package_info_plus, and share_plus:

// build.gradle.kts
val agpMajor = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.split(".").first().toInt()
if (agpMajor < 9) {
    apply(plugin = "org.jetbrains.kotlin.android")
}

Groovy equivalent:

def agpMajor = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.split("\\.")[0].toInt()
if (agpMajor < 9) {
    apply plugin: 'kotlin-android'
}

References

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