# Built-in Kotlin migration for plugin authors

> Migrate Flutter plugins to use built-in Kotlin.



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).

To verify whether your plugin applies KGP,
find the `kotlin-android` plugin
(or the `org.jetbrains.kotlin.android` plugin).
It is likely located in the
`<plugin-project>/android/build.gradle` or
`<plugin-project>/android/build.gradle.kts` file.
To view the KGP application code,
see [Update the Gradle file](#update-the-gradle-file).

If your plugin project doesn't currently apply KGP,
don't migrate to built-in Kotlin.
:::

:::note
To update Flutter apps to use built-in Kotlin,
follow the [migration guide for app developers][].
:::

[migration guide for app developers]: /release/breaking-changes/migrate-to-built-in-kotlin/for-app-developers

## Update the Gradle file

First, find the `kotlin-android` plugin
(or the `org.jetbrains.kotlin.android` plugin).
It is likely located in the `plugins` block of the
`<plugin-project>/android/build.gradle` or the `<plugin-project>/android/build.gradle.kts` file.
If you use the legacy `apply` syntax,
it will be located in the Groovy-based `<plugin-project>/android/build.gradle` file,
as this syntax isn't supported in Kotlin DSL.

The following examples demonstrate how to migrate a Flutter plugin:

<Tabs key="modern-legacy-apply">
<Tab name="Plugins block">

**Before**:

```kotlin title="<app-src>/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="<app-src>/android/build.gradle.kts"
  plugins {
      id("com.android.library")
-     id("kotlin-android")
      // ...
  }

  android {
      // ...
-     kotlinOptions {
-         jvmTarget = JavaVersion.VERSION_17.toString()
-     }
      // ...
  }
```

Add the `kotlin.compilerOptions{}` DSL block with the following:

```kotlin diff title="<app-src>/android/build.gradle.kts"
+ kotlin {
+     compilerOptions {
+         jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17
+     }
+ }
```

Here is how the file will likely end up:

**After**:

```kotlin title="<app-src>/android/build.gradle(.kts)"
plugins {
    id("com.android.library")
    // ...
}

android {
    // ...
}

kotlin {
    compilerOptions {
        jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17
    }
}

// ...
```

</Tab>
<Tab name="Legacy apply">

**Before**:

```groovy title="<app-src>/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="<app-src>/android/build.gradle"
  apply plugin: 'com.android.library'
- apply plugin: 'kotlin-android'
// ...

  android {
      // ...
-     kotlinOptions {
-         jvmTarget = JavaVersion.VERSION_17.toString()
-     }
      // ...
  }
```

Add the `kotlin.compilerOptions{}` DSL block with the following:

```groovy diff title="<app-src>/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="<app-src>/android/build.gradle"
apply plugin: 'com.android.library'
// ...

android {
    // ...
}

kotlin {
    compilerOptions {
        jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17
    }
}

// ...
```
</Tab>
</Tabs>

## Update the plugin's `pubspec.yaml`

Using the `kotlin.compilerOptions {}` DSL block requires
a minimum Kotlin Gradle Plugin (KGP) version of 2.0.0.
Beginning with Flutter 3.44, the minimum required KGP version is 2.0.0.
To ensure that apps using your plugin can build on AGP 9,
require a minimum Flutter version of 3.44 for the plugin version.
This allows apps using your plugin to build on AGP 9 with
built-in Kotlin disabled (`android.builtInKotlin=false`).

:::note
Enabling built-in Kotlin (`android.builtInKotlin=true`)
in the plugin's example app requires Flutter 3.47 or later.
:::

Because you are updating the minimum Flutter version,
you must also update the minimum associated Dart version.

Update the minimum Flutter version and the minimum Dart version:

```yaml diff title="<plugin-project>/pubspec.yaml"
# ...

  environment:
-   sdk: ^<previous-dart-minimum>
+   sdk: ^3.12.0
-   flutter: ">=<previous-flutter-minimum>"
+   flutter: ">=3.44.0"

# ...
```

Here is how the file will likely end up:

```yaml title="<plugin-project>/pubspec.yaml"
# ...

environment:
  sdk: ^3.12.0
  flutter: ">=3.44.0"

# ...
```

<FragmentTarget id="update-the-plugins-changelog-md" />

## Update the plugin's changelog

Include your changes in the `CHANGELOG.md` file of
the newly released plugin version:

```markdown diff title="<plugin-project>/CHANGELOG.md"
+ ## <new-plugin-release-version>

+ - Updates the minimum supported SDK version to Flutter 3.44/Dart 3.12.
+ - Migrates to built-in Kotlin.

// ...
```

## Validate

Before enabling built-in Kotlin,
confirm that you have migrated your plugin example app
and any Flutter plugins it uses.
Also, confirm that you updated your plugin example app
to AGP 9+, because built-in Kotlin requires AGP 9+.

To enable built-in Kotlin,
set the `android.builtInKotlin` property to `true`
in your `gradle.properties` file:

```properties diff title="<flutter-project>/android/gradle.properties"
# ...
+ android.builtInKotlin=true
```

:::version-note
Flutter 3.44 added support for AGP 9 with built-in Kotlin disabled
(`android.builtInKotlin=false`),
while enabling built-in Kotlin (`android.builtInKotlin=true`)
requires Flutter 3.47 or later.
:::

After enabling built-in Kotlin,
execute `flutter run` or `flutter build apk`
to confirm that your plugin example app builds and launches
on a connected Android device or emulator.

If your plugin example app also applies KGP,
then you will also have to migrate the example app.
To migrate your example app,
follow the [migration guide for app developers][app-migration-guide].

[app-migration-guide]: /release/breaking-changes/migrate-to-built-in-kotlin/for-app-developers

