— Flutter, Kotlin, Android, Troubleshooting, Mobile Development — 1 min read
Recently ran into that pesky Kotlin Gradle plugin error in your Flutter project? Yeah, me too. It's one of those head-scratching moments when you're ready to build your app and Flutter throws this at you:
1┌─ Flutter Fix ──────────────────────────────────────────────────────────────────────────────────────────┐2│ [!] Your project requires a newer version of the Kotlin Gradle plugin. │3│ Find the latest version on https://kotlinlang.org/docs/releases.html#release-details, then update the │4│ version number of the plugin with id "org.jetbrains.kotlin.android" in the plugins block of │5│ /Users/johnsmith/FlutterProjects/test_app/android/settings.gradle. │6│ │7│ Alternatively (if your project was created before Flutter 3.19), update │8│ /Users/johnsmith/FlutterProjects/test_app/android/build.gradle │9│ ext.kotlin_version = '<latest-version>' │10└────────────────────────────────────────────────────────────────────────────────────────────────────────┘
Don't worry – it's actually pretty simple to fix. Let me walk you through it.
There are two ways to handle this, depending on when you created your Flutter project:
Just pop open your android/settings.gradle
file and update the Kotlin plugin version. Here's what you're looking for:
1plugins {2 id 'org.jetbrains.kotlin.android' version '1.9.22' // Bump this to the latest version3 // Your other plugins will be here4}
If you're working with an older project, you'll need to update android/build.gradle
instead:
1buildscript {2 ext.kotlin_version = '1.9.22' // Just update this line3 // The rest of your buildscript block stays the same4}
Head over to the Kotlin Releases Page and grab the latest stable version. Don't be tempted by the EAP (Early Access Preview) versions unless you really know what you're doing!
After updating the version, run these commands in order:
1flutter clean2flutter pub get3flutter run
If you're still seeing red:
build.gradle
and settings.gradle
)That's really all there is to it! Hit me up in the comments if you run into any snags.
Remember: Always backup your project before messing with Gradle files. Trust me on this one.