Skip to content

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

Merged
boyan01 merged 1 commit into
MixinNetwork:mainfrom
loucass:fix/agp9-kotlin-configure
Aug 31, 2026
Merged

fix Android compatibility with AGP > 9 hosts in desktop_drop#498
boyan01 merged 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

@boyan01 boyan01 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix and the detailed verification. Looks good to me.

@boyan01
boyan01 merged commit 0e44c2f into MixinNetwork:main Aug 31, 2026
1 check passed
@ekuleshov

Copy link
Copy Markdown

hmm. I'm still getting these errors with 0.8.3 release

1: Task failed with an exception.
-----------
* Where:
Build file '**/.pub-cache/hosted/pub.dev/desktop_drop-0.8.3/android/build.gradle' line: 36

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

2: Task failed with an exception.
-----------
* What went wrong:
A problem occurred configuring project ':desktop_drop'.
> Failed to notify project evaluation listener.
   > java.lang.NullPointerException (no error message)
   > java.lang.NullPointerException (no error message)
   > Android Gradle Plugin: project ':desktop_drop' does not specify `compileSdk` in build.gradle (**/.pub-cache/hosted/pub.dev/desktop_drop-0.8.3/android/build.gradle).                                                                                                                                

@loucass

loucass commented Aug 31, 2026

Copy link
Copy Markdown
Contributor Author

@ekuleshov ok thanks. Could you try my branch fix/agp-kotlin-tasks directly to test new fixes ?

dependency_overrides:
  desktop_drop:
    git:
      url: https://github.com/loucass/flutter-plugins.git
      path: packages/desktop_drop
      ref: fix/agp-kotlin-tasks

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.

3 participants