diff --git a/sites/docs/src/content/release/breaking-changes/migrate-to-built-in-kotlin/for-plugin-authors.md b/sites/docs/src/content/release/breaking-changes/migrate-to-built-in-kotlin/for-plugin-authors.md index 069615a70d..4bea85c264 100644 --- a/sites/docs/src/content/release/breaking-changes/migrate-to-built-in-kotlin/for-plugin-authors.md +++ b/sites/docs/src/content/release/breaking-changes/migrate-to-built-in-kotlin/for-plugin-authors.md @@ -7,6 +7,14 @@ description: >- This guide outlines the migration steps specifically for plugin authors. :::warning +Migrating to built-in Kotlin requires a minimum Flutter version of 3.44. + +This migration uses `kotlin.compilerOptions {}`, +which requires Kotlin Gradle Plugin (KGP) 2.0.0 or higher. +Flutter enforces a minimum KGP version of 2.0.0 starting in Flutter 3.44. +Plugin authors must update their plugin's minimum Flutter version +to at least 3.44 in `pubspec.yaml` when migrating. + This guide only applies to plugins that already use the Kotlin Gradle Plugin (KGP). @@ -32,12 +40,6 @@ follow the [migration guide for app developers][]. ## Update the Gradle file -The following steps assume you can -update your plugin's Flutter SDK minimum to 3.44. -If you can't update the Flutter SDK minimum to 3.44, -follow the instructions to -[support Flutter versions earlier than 3.44][flutter-sdk-minimum-below-3.44]. - First, find the `kotlin-android` plugin (or the `org.jetbrains.kotlin.android` plugin). It is likely located in the `plugins` block of the @@ -192,8 +194,6 @@ kotlin { -[flutter-sdk-minimum-below-3.44]: #support-flutter-versions-earlier-than-3-44 - ## Update the plugin's `pubspec.yaml` Using the `kotlin.compilerOptions {}` DSL block requires @@ -238,193 +238,6 @@ environment: # ... ``` - - -## Support Flutter versions earlier than 3.44 - -If you updated your plugin's Flutter SDK minimum to 3.44, -skip this section and proceed to -[updating the plugin's `CHANGELOG.md`](#update-the-plugins-changelog). - -If you can't update the plugin's Flutter SDK minimum to 3.44, you must -make the following changes to `/android/build.gradle` or -`/android/build.gradle.kts` to -support apps on AGP versions less than 9 and versions on 9 or later. - - - - -**Before**: - -```kotlin title="/android/build.gradle.kts" -plugins { - id("com.android.library") - id("kotlin-android") - // ... -} - -android { - // ... - kotlinOptions { - jvmTarget = JavaVersion.VERSION_17.toString() - } - // ... -} - -// ... -``` - -Next, remove the `kotlin-android` plugin and the `kotlinOptions` block: - -```kotlin diff title="/android/build.gradle.kts" - plugins { - id("com.android.library") -- id("kotlin-android") - // ... - } - - android { - // ... -- kotlinOptions { -- jvmTarget = JavaVersion.VERSION_17.toString() -- } - // ... - } -``` - -Add a check to apply the Kotlin Gradle Plugin only when -the app's Android Gradle Plugin version is less than version 9. - -```kotlin diff title="/android/build.gradle.kts" -+ val agpMajor = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.substringBefore('.').toInt() -+ -+ if (agpMajor < 9) { -+ apply(plugin = "org.jetbrains.kotlin.android") -+ } -``` - -Add the `compilerOptions` configuration using the project extension: - -```kotlin diff title="/android/build.gradle.kts" -+ project.extensions.configure(org.jetbrains.kotlin.gradle.dsl.KotlinAndroidProjectExtension::class.java) { -+ compilerOptions { -+ jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17 -+ } -+ } -``` - -Here is how the file will likely end up: - -**After**: - -```kotlin title="/android/build.gradle.kts" -plugins { - id("com.android.library") - // ... -} - -val agpMajor = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.substringBefore('.').toInt() - -if (agpMajor < 9) { - apply(plugin = "org.jetbrains.kotlin.android") -} - -android { - // ... -} - -project.extensions.configure(org.jetbrains.kotlin.gradle.dsl.KotlinAndroidProjectExtension::class.java) { - compilerOptions { - jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17 - } -} - -// ... -``` - - - - -**Before**: - -```groovy title="/android/build.gradle" -apply plugin: 'com.android.library' -apply plugin: 'kotlin-android' - -android { - // ... - kotlinOptions { - jvmTarget = JavaVersion.VERSION_17.toString() - } - // ... -} - -// ... -``` - -Next, remove the `kotlin-android` plugin and the `kotlinOptions` block: - -```groovy diff title="/android/build.gradle" - apply plugin: 'com.android.library' -- apply plugin: 'kotlin-android' - - android { - // ... -- kotlinOptions { -- jvmTarget = JavaVersion.VERSION_17.toString() -- } - // ... - } -``` - -Add a check to apply the Kotlin Gradle Plugin only when -the app's Android Gradle Plugin version is less than version 9. - -```groovy diff title="/android/build.gradle" -+ def agpMajor = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')[0] as int -+ -+ if (agpMajor < 9) { -+ apply plugin: 'kotlin-android' -+ } -``` - -Add the `kotlin.compilerOptions{}` DSL block with the following: - -```groovy diff title="/android/build.gradle" -+ kotlin { -+ compilerOptions { -+ jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17 -+ } -+ } -``` - -Here is how the file will likely end up: - -**After**: - -```groovy title="/android/build.gradle" -apply plugin: 'com.android.library' - -def agpMajor = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')[0] as int -if (agpMajor < 9) { - apply plugin: 'kotlin-android' -} - -android { - // ... -} - -kotlin { - compilerOptions { - jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17 - } -} - -// ... -``` - - - ## Update the plugin's changelog