This short article shows you how to solve a problem you might encounter when developing an Android app with Flutter.
The Error
When trying to start a Flutter project with an Android emulator, I ran into the following issue:
Your project requires a newer version of the Kotlin Gradle plugin
This project was created months ago. Here’s the detailed error message:
BUILD FAILED in 1m 2s
Running Gradle task 'assembleDebug'... 64.3s
Flutter Fix ───────────────────────────────────────────────────────────────────
[!] Your project requires a newer version of the Kotlin Gradle plugin.
Find the latest version on https://kotlinlang.org/docs/gradle.html#plugin-and-versions, then update
/Users/goodman/Desktop/Projects/kindacode/android/build.gradle:
ext.kotlin_version = '<latest-version>'
───────────────────────────────────────────────────────────────────
Exception: Gradle task assembleDebug failed with exit code 1
If you confront the same error as mine, don’t panic. The solution isn’t hard to follow.
Solution
All you need to do is to open the <your project>/android/build.gradle file then update ext.kotlin_version to a newer version. The screenshot below clearly depicts what I mean (but don’t use version 1.6.10 since it is too old. You will see how to find a proper version number just after this picture):
At the time of writing, the latest version is 1.8.10. However, things change over time. To get the update-to-date version number of the Kotlin Gradle plugin, go to https://docs.gradle.org/current/userguide/compatibility.html#kotlin.
Now run your project again, and it should work as expected:
That’s it. Further reading:
- Flutter: Changing App Display Name for Android & iOS
- 3 Ways to Cancel a Future in Flutter and Dart
- Flutter StreamBuilder examples (null safety)
- Flutter: SliverGrid example
- Flutter: Creating an Auto-Resize TextField
You can also check out our Flutter category page or Dart category page for the latest tutorials and examples.
do i also need to upgrade the packages? because if packages built using older kotlin, they wont work if you upgrade the main project’s kotlin version. Isnt it?
Have you found the solution?
See the “Solution” section