Skip to content

fix: use builtInKotlin property to conditionally apply KGP - #500

Merged
boyan01 merged 4 commits into
MixinNetwork:mainfrom
loucass:fix/agp-kotlin-tasks
Sep 1, 2026
Merged

fix: use builtInKotlin property to conditionally apply KGP#500
boyan01 merged 4 commits into
MixinNetwork:mainfrom
loucass:fix/agp-kotlin-tasks

Conversation

@loucass

@loucass loucass commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Problem

desktop_drop 0.8.2 and 0.8.3 failed to compile Kotlin on one AGP version or the other:

  • AGP 8: kotlin() not found — no Kotlin extension without KGP applied
  • AGP 9.1 (Flutter 3.44, builtInKotlin=false): kotlin() not found — AGP 9 doesn't register the extension for plugin subprojects; tasks.withType(KotlinCompile) found no tasks to configure

Every conditional approach (if/else on agpMajor, tasks.withType) broke one side because on Flutter 3.44, builtInKotlin=false means AGP 9 does NOT automatically provide Kotlin for plugins. The plugin must apply KGP itself.

Solution

Branch on the android.builtInKotlin Gradle property instead of the AGP version number:

  • builtInKotlin=false → apply KGP + use kotlinOptions (AGP 8, or AGP 9 with Flutter <3.47)
  • builtInKotlin=true → skip KGP + use compilerOptions (AGP 9 with Flutter 3.47+)

This is more precise than checking agpMajor because it directly reads whether AGP provides Kotlin built-in, rather than guessing from the version number. It avoids the KGP non-compliance warning on hosts where it's not needed.

Changes

  • android/build.gradle: Read android.builtInKotlin property. Conditionally apply kotlin-android and use the appropriate DSL (kotlinOptions vs compilerOptions).

Testing

Both AGP paths verified:

Host Config builtInKotlin Result
AGP 8.12 Flutter 3.47, Gradle 8.14 false ✅ Applies KGP, kotlinOptions
AGP 9.1 Flutter 3.44+, Gradle 9.1+, KGP 2.3.20 false ✅ Applies KGP, kotlinOptions
AGP 9 Flutter 3.47+, builtInKotlin=true true ✅ Skips KGP, compilerOptions

@loucass
loucass marked this pull request as draft August 31, 2026 17:38
@loucass loucass changed the title fix: use tasks.withType for Kotlin jvmTarget to support both AGP 8 and AGP 9 fix: apply KGP unconditionally to support both AGP 8 and 9 Sep 1, 2026
@loucass
loucass marked this pull request as ready for review September 1, 2026 12:23
@boyan01

boyan01 commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

this PR seems reverted the migrations.

I suppose an agpMajor condition for apply plugin: 'kotlin-android' is needed

Copilot AI 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.

Pull request overview

Restores Android Kotlin compilation compatibility and prepares desktop_drop 0.8.4.

Changes:

  • Applies KGP unconditionally and configures JVM 1.8.
  • Bumps the package version and updates the changelog.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
packages/desktop_drop/android/build.gradle Revises Kotlin plugin configuration.
packages/desktop_drop/pubspec.yaml Bumps version to 0.8.4.
packages/desktop_drop/CHANGELOG.md Documents the Android fix.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread packages/desktop_drop/android/build.gradle Outdated
@loucass

loucass commented Sep 1, 2026

Copy link
Copy Markdown
Contributor Author

@boyan01 I tried the agpMajor conditional approach first, but it fails on AGP 9 with Flutter 3.44 (which uses builtInKotlin=false). On that combination, AGP 9 does NOT provide KGP for plugin subprojects — the plugin must apply KGP itself. Skipping it causes DesktopDropPlugin class not found.

Tested here: #498 (comment)

The KGP warning is non-fatal on Flutter 3.44–3.46 (tracked at flutter/flutter#189770). When Flutter 3.47+ makes it fatal (#498 (comment)), but unconditional apply is the only approach that works on all current AGP + Flutter combinations.

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

@loucass
loucass marked this pull request as draft September 1, 2026 12:53
@loucass

loucass commented Sep 1, 2026

Copy link
Copy Markdown
Contributor Author

@boyan01 @ekuleshov
Update: I've now refined the approach based on your feedback. Instead of unconditional apply, I'm branching on the android.builtInKotlin Gradle property:

  • builtInKotlin=false → apply KGP + kotlinOptions
  • builtInKotlin=true → skip KGP + compilerOptions

This is more precise than agpMajor because it directly checks whether AGP provides Kotlin built-in, rather than guessing from the version number. It avoids the KGP warning on hosts where it's not needed.

@loucass
loucass marked this pull request as ready for review September 1, 2026 13:04
@loucass loucass changed the title fix: apply KGP unconditionally to support both AGP 8 and 9 fix: use builtInKotlin property to conditionally apply KGP Sep 1, 2026
// Apply KGP only when AGP does not provide built-in Kotlin.
// builtInKotlin=true -> AGP 9+ with Flutter 3.47+ provides Kotlin built-in, skip KGP
// builtInKotlin=false -> AGP 8 or AGP 9+ with Flutter <3.47, must apply KGP explicitly
def builtInKotlin = project.hasProperty('android.builtInKotlin') &&

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.

[P1] Treat a missing android.builtInKotlin property as enabled on AGP 9+

This currently maps a missing property to false, but AGP 9 and Flutter 3.47 default built-in Kotlin to enabled unless the property is explicitly set to false. With AGP 9.1 and the property omitted, this branch reaches apply plugin: kotlin-android and fails during project evaluation because AGP 9 rejects KGP while built-in Kotlin is active. I reproduced this using the checked-in Example at this PR SHA: explicit true passes, explicit false passes through the legacy path, and an absent property fails at line 26.

Please include the AGP major version in this calculation and use the same semantics as Flutter: AGP <9 is always false; AGP 9+ is true unless the property is explicitly false.

@loucass

loucass commented Sep 1, 2026

Copy link
Copy Markdown
Contributor Author

@boyan01
Applied. Added the agpMajor fallback so AGP 9+ defaults to builtInKotlin=true when the property is absent.

@boyan01
boyan01 merged commit 2ef30a7 into MixinNetwork:main Sep 1, 2026
1 check passed
@boyan01

boyan01 commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Thank you for your patience in fixing this. LGTM

loucass added a commit to loucass/localsend that referenced this pull request Sep 3, 2026
0.8.3 still fails to compile Kotlin on some AGP/Flutter combos; 0.8.4
branches on the android.builtInKotlin property (MixinNetwork/flutter-plugins#500).

Generated with Codebuff 🤖
Co-Authored-By: Codebuff <noreply@codebuff.com>
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