Skip to content

Migrate to Flutter's built-in Kotlin (Flutter 3.44+) - #139

Merged
jonasbark merged 1 commit into
masterfrom
fix/migrate-to-built-in-kotlin
Jul 3, 2026
Merged

jonasbark merged 1 commit into
masterfrom
fix/migrate-to-built-in-kotlin

Conversation

@jonasbark

Copy link
Copy Markdown
Owner

Closes #137

Flutter 3.44 requires plugin authors to rely on Flutter's built-in Kotlin instead of applying the Kotlin Gradle Plugin themselves (migration guide). This migrates both the plugin and the example app.

Plugin (android/build.gradle)

  • Removed apply plugin: 'kotlin-android' and the org.jetbrains.kotlin:kotlin-gradle-plugin classpath — Kotlin is now provided by Flutter's built-in Kotlin support.
  • Replaced the deprecated kotlinOptions { jvmTarget = '1.8' } block with kotlin { compilerOptions { jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_1_8 } } (kept JVM_1_8 to preserve the plugin's existing Java 8 target).
  • Bumped KGP 2.2.10 → 2.2.20 (the minimum Flutter now recommends).

Example app (example/android/)

  • Migrated to built-in Kotlin per the for-app-developers guide: removed kotlin-android from the app's plugins {} block, dropped kotlinOptions, and switched to the kotlin { compilerOptions } DSL.
  • Set android.builtInKotlin=true and android.newDsl=true in gradle.properties so flutter build no longer keeps re-writing the =false opt-out flags.
  • Bumped the KGP declaration in settings.gradle to 2.2.20.

Version

  • Breaking: bumped to 5.0.0; pubspec.yaml now requires flutter: ">=3.44.0" / sdk: ^3.12.0.

Note: org.jetbrains.kotlin.android kept in example settings.gradle

The for-app-developers guide suggests removing that plugin declaration entirely, but I intentionally kept it (bumped to 2.2.20). On AGP 8.13 (what the example uses), built-in Kotlin still sources the Kotlin compiler version from that declaration. Removing it makes the compiler fall back to 2.0.0, which is incompatible with the 2.2.20 stdlib and fails the build with Module was compiled with an incompatible version of Kotlin. The guide's "remove it" step only applies once the project is on AGP 9 with bundled Kotlin.

Verification

Verified end-to-end against Flutter 3.45.0 / Dart 3.12.1 / Java 21 / AGP 8.13:

  • flutter build apk --debug on the example → builds successfully.
  • Confirmed flutter build no longer re-adds builtInKotlin=false / newDsl=false.
  • Confirmed the plugin compiles for consumers whether or not their own app has migrated (built builtInKotlin both true and false).
  • The "applies the Kotlin Gradle Plugin" warnings and the KGP-version warning are gone.

Remaining (out of scope, pre-existing): Flutter warns that Gradle 8.13.0 will soon be unsupported (wants ≥ 8.14.0) — a wrapper-version bump unrelated to this change.

🤖 Generated with Claude Code

Flutter 3.44 requires plugin authors to use Flutter's built-in Kotlin
instead of applying the Kotlin Gradle Plugin themselves.

- android/build.gradle: drop `apply plugin: 'kotlin-android'` and the KGP
  classpath, replace the `kotlinOptions` block with `kotlin { compilerOptions }`
  (JVM_1_8 to preserve the Java 8 target), and bump KGP to 2.2.20
- example app: migrate to built-in Kotlin (builtInKotlin/newDsl = true,
  remove kotlin-android, use the kotlin { compilerOptions } DSL)
- require Flutter 3.44 / Dart 3.12 and bump to 5.0.0 (breaking)

Fixes #137

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings July 3, 2026 20:35

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Migrates the plugin and example Android project to Flutter 3.44+ “built-in Kotlin” support, removing direct Kotlin Gradle Plugin application and aligning Kotlin/JVM compiler configuration with the new recommended DSL. This is released as a breaking change by bumping the package to 5.0.0 and raising the minimum Flutter/Dart SDK constraints.

Changes:

  • Raise minimum SDK constraints and bump package version to 5.0.0 (Flutter >= 3.44.0, Dart ^3.12.0).
  • Android migration: stop applying/declaring the Kotlin Gradle Plugin in the plugin module; switch from kotlinOptions to kotlin { compilerOptions }.
  • Example app migration: enable android.builtInKotlin + android.newDsl, remove kotlin-android from the app module, and bump Kotlin plugin declaration to 2.2.20.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
pubspec.yaml Bumps major version and raises minimum Flutter/Dart constraints for the breaking migration.
CHANGELOG.md Documents the 5.0.0 breaking change and Kotlin migration details.
android/build.gradle Removes KGP classpath/application and switches Kotlin JVM target configuration to compilerOptions.
example/android/app/build.gradle Removes kotlin-android plugin and moves JVM target to kotlin { compilerOptions }.
example/android/gradle.properties Enables android.builtInKotlin=true and android.newDsl=true to prevent Flutter from rewriting opt-out flags.
example/android/settings.gradle Bumps org.jetbrains.kotlin.android declaration to 2.2.20 for the example project.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@jonasbark
jonasbark merged commit 02f0e48 into master Jul 3, 2026
1 check passed
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.

Stop using kotlin gradle plugin.

2 participants