Skip to content

cryptography_flutter: applies Kotlin Gradle Plugin unconditionally, breaks AGP 9 built-in Kotlin #229

Description

@jovinlidan

Thanks for maintaining this package.

Problem

cryptography_flutter/android/build.gradle applies the Kotlin Gradle Plugin unconditionally:

// line 13
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version")
// line 25
apply plugin: "kotlin-android"

AGP 9 ships built-in Kotlin (it supplies the Kotlin toolchain itself) and no longer permits a module to apply KGP. With android.builtInKotlin=true, the build hard-fails:

Failed to apply plugin 'com.android.internal.library'.
> The 'org.jetbrains.kotlin.android' plugin is no longer required for Kotlin support since AGP 9.0.

Flutter also warns on every Android build and states that future Flutter versions will fail to build if any plugin applies KGP:

WARNING: Your app uses the following plugins that apply Kotlin Gradle Plugin (KGP): ... cryptography_flutter ...
Future versions of Flutter will fail to build if your app uses plugins that apply KGP.

Because the flag is project-wide and all-or-nothing, a single plugin that still applies KGP prevents the whole app from migrating.

Suggested fix

Apply KGP only on AGP < 9, which keeps older toolchains working. Several plugins have already adopted this shape (e.g. no_screenshot 1.2.0, mobile_scanner 7.4.0):

def agpMajor = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize(".")[0] as int
if (agpMajor < 9) {
    apply plugin: "kotlin-android"
}

// `kotlin {}` is registered by KGP on AGP < 9 and by built-in Kotlin on 9+
kotlin {
    compilerOptions {
        jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_1_8
    }
}

Two related notes:

  • kotlinOptions { } (line 37) is the KGP-only DSL; kotlin { compilerOptions { } } works on both paths.
  • main.java.srcDirs += "src/main/kotlin" (line 42) should be dropped under built-in Kotlin — the Kotlin toolchain already compiles that directory, and registering it again produces "Conflicting declarations" on recent Flutter versions.

References:

Environment

  • cryptography_flutter 2.3.4
  • Flutter 3.44.2 (stable)
  • AGP 9.1.1, Gradle 9.3.1

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