Skip to content

[compat][android] android_id plugin incompatible with AGP 9.0+ — build fails (kotlin-android & proguard) #119

@raph5640

Description

@raph5640

After adding/patching the android_id plugin (v0.5.1) to my Flutter project, Release builds fail with errors related to Kotlin / AGP 9 and ProGuard/R8. The build succeeds if I remove the plugin, so the problem appears only when the plugin is present.

The plugin's android/build.gradle applies kotlin-android and declares its own buildscript/classpath for AGP/Kotlin, for example:

buildscript {
classpath("com.android.tools.build:gradle:8.7.2")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version")
}
apply plugin: "com.android.library"
apply plugin: "kotlin-android"
...
kotlinOptions {
jvmTarget = "17"
}

(See flutter/patchs/android_id-0.5.1/android/build.gradle.)

Observed errors (examples)

When evaluating project :android_id:
Failed to apply plugin 'kotlin-android'.

Failed to apply plugin 'org.jetbrains.kotlin.android'
The 'org.jetbrains.kotlin.android' plugin is no longer required for Kotlin support since AGP 9.0.
Solution: Remove the 'org.jetbrains.kotlin.android' plugin from this project's build file...

Later during release build:
Execution failed for task ':app:minifyReleaseWithR8'.

Supplied proguard configuration does not exist:
...\android\app\build\intermediates\default_proguard_files\global\proguard-android-optimize.txt-9.1.0

Diagnosis

AGP 9+ ships Kotlin built-in. Applying kotlin-android with AGP 9+ causes the "Failed to apply plugin 'org.jetbrains.kotlin.android'" error.
The plugin declares its own buildscript/classpath for AGP and the Kotlin Gradle plugin. When a plugin module defines or forces its own AGP/Kotlin classpath or AGP behaviour, this can break AGP/Gradle alignment between the root project and plugin modules. One symptom is that AGP fails to generate the default ProGuard files (the default_proguard_files under build/intermediates), which leads to the missing proguard-android-optimize.txt- error when R8 runs.
Root cause: the plugin should not force an AGP/Kotlin classpath nor apply kotlin-android. The root project must control AGP/Kotlin versions. Also kotlinOptions {...} must be migrated to the AGP 9+ Kotlin DSL.

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