Skip to content

Specifying Kotlin Version in Flutter Projects After 3.19.2 Update

Problem Statement

With Flutter 3.19.2, the buildscript block was removed from the /android/build.gradle file, eliminating the previous location for the Kotlin version declaration (ext.kotlin_version). This change leaves developers uncertain about where to specify Kotlin versions for Gradle to use. When attempting to build Android applications with this Flutter version, you may encounter errors like:

Flutter version 3.19.2 requires a newer version of the Kotlin Gradle plugin

Solution Overview

Starting with Flutter 3.16+, the Kotlin version is now specified in android/settings.gradle (or settings.gradle.kts for Kotlin DSL projects). This is part of Flutter's migration to Gradle's Plugin DSL syntax. Follow these steps to resolve version conflicts:

Step 1: Modify settings.gradle

Open android/settings.gradle and locate the plugins block. Update the Kotlin Android plugin version:

groovy
plugins {
    id "dev.flutter.flutter-plugin-loader" version "1.0.0"
    id "com.android.application" version "8.1.2" apply false
    id "org.jetbrains.kotlin.android" version "1.8.0" apply false // Update this version
}

Replace 1.8.0 with the latest stable Kotlin version from the official Kotlin releases. For example:

groovy
plugins {
    id "dev.flutter.flutter-plugin-loader" version "1.0.0"
    id "com.android.application" version "8.1.2" apply false
    id "org.jetbrains.kotlin.android" version "2.0.20" apply false
}

For Kotlin DSL users (settings.gradle.kts)

kotlin
plugins {
    id("dev.flutter.flutter-plugin-loader") version "1.0.0"
    id("com.android.application") version "8.1.2" apply false
    id("org.jetbrains.kotlin.android") version "2.0.20" apply false // Update this version
}

Step 2: Resolve Cache Issues

After updating the version, clean project artifacts to prevent caching conflicts:

bash
flutter clean
cd android
./gradlew cleanBuildCache

TIP

If Gradle cache issues persist:

  1. Delete %USERPROFILE%/.gradle/caches
  2. Run Windows Resource Monitor (resmon)
  3. Terminate any java.exe processes locking Gradle files

Why This Change Occurred

Flutter migrated to Gradle's Plugin DSL to adopt modern build configuration practices. According to Flutter's breaking changes documentation:

  • Projects created with Flutter ≥3.16 require Plugin DSL syntax
  • Manual migration is needed for projects created before Flutter 3.16
  • Equivalent app binaries are maintained through the transition

Confirming Your Kotlin Version

The minimum compatible Kotlin version changes with Flutter updates. You can verify compatibility using these methods:

  1. Create a new Flutter project with flutter create test_project
  2. Inspect test_project/android/settings.gradle for the default version
  3. Compare with your existing project configuration

Avoid Outdated Solutions

Some answers suggest modifying android/build.gradle or app/build.gradle. This is no longer required and may cause conflicts.

FAQ

Where do I find valid Kotlin versions?
Always use versions listed on the official Kotlin releases page.

Can I use Kotlin DSL with Flutter?
Yes, rename settings.gradlesettings.gradle.kts and translate Groovy syntax to Kotlin. Keep plugin versions identical.

What if errors persist after updating?

  1. Verify Android Gradle Plugin version compatibility with Kotlin
  2. Ensure no legacy plugin declarations remain in app/build.gradle
  3. Check for version typos in settings.gradle