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 pluginSolution 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:
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:
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)
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:
flutter clean
cd android
./gradlew cleanBuildCacheTIP
If Gradle cache issues persist:
- Delete
%USERPROFILE%/.gradle/caches - Run Windows Resource Monitor (
resmon) - Terminate any
java.exeprocesses 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:
- Create a new Flutter project with
flutter create test_project - Inspect
test_project/android/settings.gradlefor the default version - 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.gradle → settings.gradle.kts and translate Groovy syntax to Kotlin. Keep plugin versions identical.
What if errors persist after updating?
- Verify Android Gradle Plugin version compatibility with Kotlin
- Ensure no legacy plugin declarations remain in
app/build.gradle - Check for version typos in
settings.gradle