Skip to content

desktop_drop: restore Android compatibility with AGP < 9 hosts - #495

Merged
boyan01 merged 1 commit into
MixinNetwork:mainfrom
loucass:add-agp-version-compatibility
Aug 26, 2026
Merged

desktop_drop: restore Android compatibility with AGP < 9 hosts#495
boyan01 merged 1 commit into
MixinNetwork:mainfrom
loucass:add-agp-version-compatibility

Conversation

@loucass

@loucass loucass commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Problem

desktop_drop 0.8.1 failed at configuration time on every app using AGP < 9 (localsend for example) with:

Build file '.../desktop_drop-0.8.1/android/build.gradle' line: 48
* What went wrong:
A problem occurred evaluating project ':desktop_drop'.
> Could not find method kotlin() for arguments [...] on project ':desktop_drop'

This affects all apps below Flutter 3.44 — they cannot simply move to AGP 9,
because Flutter itself only supports AGP 9 from 3.44+
(built-in Kotlin migration guide).
For those apps, the 0.8.0 changelog note ("must use AGP 9 or later") is unsatisfiable.

Root cause

android/build.gradle calls kotlin { compilerOptions {} } but never applies KGP:

Host Who compiles Kotlin? Unconditional kotlin{} Conditional apply
AGP < 9 nobody → plugin must apply KGP itself kotlin() not found ✅ applies KGP itself
AGP ≥ 9 AGP built-in Kotlin ✅ works ✅ skips — hard error if applied

The example app (AGP 9.1) only ever exercised the second row, which is why this went
unnoticed. An alternative fix — raising the plugin's minimum to Flutter 3.44 — would
lock out apps on older stable versions; the conditional keeps every host working.

Fix

Implements the official guide section
"Support Flutter versions earlier than 3.44":

  • apply kotlin-android only when host AGP major < 9
  • bump bundled KGP 1.9.252.2.0, since the kotlin.compilerOptions {} DSL requires KGP ≥ 2.0

No Dart or Kotlin changes.

Verification

  • AGP < 9 host: real app (LocalSend) builds its debug APK green on
    Flutter 3.41.9 · AGP 8.12.1 · Gradle 8.13 against this branch :
    run
    (✓ Built app-debug.apk; without the patch this same build fails at
    configuration time, before any compilation starts)
  • AGP ≥ 9 host: example app builds green on AGP 9.1 · Gradle 9.3.1 · Flutter 3.47.1 :
    run

Could you tag a desktop_drop v0.8.2 after merge so downstream apps can pick this up? Thanks!

@boyan01
boyan01 merged commit 966f0bd into MixinNetwork:main Aug 26, 2026
1 check passed
@ekuleshov

Copy link
Copy Markdown

With this change I'm getting the error below with Gradle 9.1.0 and Flutter 3.44.8.
desktop_drop 0.8.1 works

> Could not find method kotlin() for arguments [...] on project ':desktop_drop' of type org.gradle.api.Project.  

@loucass

loucass commented Aug 28, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @ekuleshov for testing — that's a regression on the AGP 9 path.

You are on AGP 9.1 + Flutter 3.44.8 where built-in Kotlin should provide the kotlin {} extension, but my change bumped the bundled KGP to 2.2.0 and kept the direct kotlin {} DSL. On AGP 9 hosts that DSL can fail when KGP isn't applied (the extension is registered differently).

Fix: use the Flutter docs' recommended conditional pattern that works on both AGP < 9 and AGP 9+:

def agpMajor = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')[0] as int
if (agpMajor < 9) {
    apply plugin: 'kotlin-android'
}
project.extensions.configure(org.jetbrains.kotlin.gradle.dsl.KotlinAndroidProjectExtension) {
    compilerOptions { jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_1_8 }
}

And keep ext.kotlin_version compatible with the host (or keep 1.9.25 for now).

I'll open a follow-up PR with that fix. Could you confirm your app/android/settings.gradle AGP version and gradle-wrapper.properties Gradle version? Want to make sure we cover Gradle 9.1 correctly.

@ekuleshov

Copy link
Copy Markdown

id("org.jetbrains.kotlin.android") version "2.3.20" apply false

distributionUrl=https\://services.gradle.org/distributions/gradle-9.1.0-bin.zip

Also my app's jvmTarget is set to JvmTarget.JVM_17 for both java and kotlin code

@loucass

loucass commented Aug 28, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the details @ekuleshov Gradle 9.1 + KGP 2.3.20 + AGP 9.1 is exactly the combo that broke.

The issue was the direct kotlin {} DSL: on AGP 9 where built-in Kotlin is used, that extension isn't available as a direct method when KGP isn't applied.

Pushed a fix to branch fix/agp9-kotlin-configure that uses the robust form:

project.extensions.configure(org.jetbrains.kotlin.gradle.dsl.KotlinAndroidProjectExtension) {
    compilerOptions { jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17 }
}

This works whether the extension comes from KGP (AGP <9) or from AGP 9's built-in.

I'm working on the fix

@loucass

loucass commented Aug 29, 2026

Copy link
Copy Markdown
Contributor Author

@ekuleshov I have just opened #498

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