Skip to content

fix(android): migrate to Built-in Kotlin - #17

Open
ilja-radusch wants to merge 2 commits into
muxable:mainfrom
ilja-radusch:builtin-kotlin
Open

ilja-radusch wants to merge 2 commits into
muxable:mainfrom
ilja-radusch:builtin-kotlin

Conversation

@ilja-radusch

Copy link
Copy Markdown

Closes #16.

This follows the Flutter guide for plugin authors: https://docs.flutter.dev/release/breaking-changes/migrate-to-built-in-kotlin/for-plugin-authors

Changes

  • android/build.gradle:
    • Drop the buildscript block (KGP 1.9.10 and the AGP 7.3.1 classpath; the app supplies both), apply plugin: 'kotlin-android', and the explicit kotlin-stdlib dependency.
    • Set the JVM target through the top-level kotlin { compilerOptions { ... } } block.
  • Replace jvmToolchain(17) with Java/Kotlin bytecode target 17. Same output, but Gradle no longer needs an exact JDK 17 installed; any JDK ≥ 17 builds it.
  • pubspec.yaml: require Flutter 3.44 / Dart 3.12, as the guide asks. From 3.44, a migrated plugin builds in apps with android.builtInKotlin=false (Flutter's current default) as well as true.
  • CHANGELOG.md: entry under "Unreleased". I left version alone; since the minimum SDK goes up, 1.3.0 seems right, but that's your call.

Testing

We have been running this exact android/build.gradle in our app (Flutter 3.50, AGP 9.3.1, Gradle 9.5.1, builtInKotlin=false):

  • The KGP warning no longer lists thermal.
  • Debug APK and release AAB (R8) both build, and ThermalPlugin is in the dex.
  • :thermal:compileDebugKotlin and the full app assemble succeed with only a JDK 21 visible to Gradle (org.gradle.java.installations.auto-detect=false).

I did not touch the example app. It still uses Gradle 7.0.2 with the imperative flutter.gradle apply, which current Flutter no longer supports. Updating it is a larger, separate change.

Flutter 3.50 warns that plugins applying the Kotlin Gradle Plugin will
fail to build in a future release (muxable#16).

- drop the buildscript block (KGP 1.9.10, AGP 7.3.1 classpath; both
  supplied by the app), the kotlin-android plugin and the explicit
  kotlin-stdlib dependency
- set the JVM target via the top-level kotlin.compilerOptions block
- replace jvmToolchain(17) with Java/Kotlin bytecode target 17, so
  builds no longer need an exact JDK 17 installed
- require Flutter 3.44 / Dart 3.12, from which a migrated plugin builds
  in apps with android.builtInKotlin=false as well as true

Closes muxable#16
Flutter 3.47 deprecated package:flutter/material.dart; CI's flutter
analyze on stable (3.50) fails on the example's import, so every PR
goes red regardless of its change.
@ilja-radusch

Copy link
Copy Markdown
Author

The earlier analyze failure didn't come from this change. flutter analyze on stable 3.50 flags the example's package:flutter/material.dart import, which has been deprecated since 3.47, so main would fail CI the same way today. I pushed 9530363, which moves the example to material_ui; flutter analyze is clean locally. The new CI run is waiting for workflow approval.

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.

Android: migrate to Built-in Kotlin (Flutter warns plugins applying KGP will fail to build)

1 participant