Skip to content

fix Android compatibility with AGP > 9 hosts in desktop_drop - #498

Open
loucass wants to merge 1 commit into
MixinNetwork:mainfrom
loucass:fix/agp9-kotlin-configure
Open

fix Android compatibility with AGP > 9 hosts in desktop_drop#498
loucass wants to merge 1 commit into
MixinNetwork:mainfrom
loucass:fix/agp9-kotlin-configure

Conversation

@loucass

@loucass loucass commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

Follow-up to #495@ekuleshov reported that 0.8.2 (Gradle 9.1.0 + Flutter 3.44.8) still fails with the same Could not find method kotlin() error that #495 was meant to fix.

Problem

0.8.2 made the apply plugin: 'kotlin-android' line conditional on AGP major < 9, but left the Kotlin configuration block unconditional:

  • android { kotlinOptions { jvmTarget } } — the pre-AGP-9 form, removed in AGP 9

Result: AGP 8 hosts now passed, but AGP 9.1 hosts failed on the kotlin {} DSL itself (kotlin() not found when KGP wasn't applied).

Root cause

Host Who compiles Kotlin? kotlin {} unconditional Conditional (this PR)
AGP < 9 nobody → plugin must apply KGP itself kotlin() not found* android.kotlinOptions branch
AGP ≥ 9 AGP built-in Kotlin ✅ works kotlin.compilerOptions branch

*kotlin extension only exists after KGP is applied.

Fix

Make the configuration block itself conditional:

def agpMajor = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')[0] as int
if (agpMajor < 9) {
    apply plugin: 'kotlin-android'
    android {
        kotlinOptions {
            jvmTarget = JavaVersion.VERSION_1_8.toString()
        }
    }
} else {
    kotlin {
        compilerOptions {
            jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_1_8
        }
    }
}

Verification

  • AGP < 9 host: LocalSend debug APK on Flutter 3.41.9 · AGP 8.12.1 · Gradle 8.13 — run (✓ Built app-debug.apk)
  • AGP 9 host: desktop_drop example on AGP 9.1 · Gradle 9.3.1 · Flutter 3.47.1 — run

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.

1 participant