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

@ekuleshov

Copy link
Copy Markdown

@loucass with that override the plugin is being reported as non-compliant:

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

and then build fail with this:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileReleaseJavaWithJavac'.
> Compilation failed; see the compiler output below.
  **/android/app/src/main/java/io/flutter/plugins/GeneratedPluginRegistrant.java:39: error: cannot find symbol                                                                                                                                                 
        flutterEngine.getPlugins().add(new one.mixin.desktop.drop.DesktopDropPlugin());
                                                                 ^
    symbol:   class DesktopDropPlugin
    location: package one.mixin.desktop.drop
  1 error

@loucass

loucass commented Sep 1, 2026

Copy link
Copy Markdown
Contributor Author

@ekuleshov ok since all the if/else approach didn't work either
I've reverted to the unconditional apply plugin: 'kotlin-android' approach from 0.7.1. Could you test branch fix/agp-kotlin-tasks again please to verify this approach ?

@ekuleshov

Copy link
Copy Markdown

@loucass it builds with the same warning

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

take a look at this one:

https://github.com/781flyingdutchman/background_downloader/blob/7bbf0f15330ef22427bbc019049a5ed80ae867b2/android/build.gradle#L6-L10

@boyan01

boyan01 commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

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

Ignore this warning. Flutter uses regular expression scanning, and it will issue a warning whenever apply plugin: 'kotlin-android' is present. We've already handled this, so let Flutter fix it themselves.

relate to flutter/flutter#189770

@loucass

loucass commented Sep 1, 2026

Copy link
Copy Markdown
Contributor Author

so happy to hear that it finally have built !!
Thanks again @ekuleshov for testing all the iterations with me and confirming the fix builds on your AGP 9.1 setup.

The unconditional KGP apply approach is the final solution same pattern as background_downloader and proven on both AGP 8 and 9. PR with the full fix is at #500 @boyan01

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