The Error “Your project requires a newer version of the Kotlin Gradle plugin.”, is an error that is invoked when you are working on android studio and have recently updated your flutter project packages. Given below is the snippet of the error you might get:
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 project/android/build.gradle:
ext.kotlin_version = '<latest-version>'
Exception: Gradle task assembleDebug failed with exit code 1
I would like to share with you the steps I took to fix the “Your project requires a newer version of the Kotlin Gradle plugin.”
Why “Your project requires a newer version of the Kotlin Gradle plugin.” Error is Seen?
The error, “Your project requires a newer version of the Kotlin Gradle plugin.” is seen because, as the error says you are using an old and outdated version of kotlin gradle plugin. Also sometime error is seen because you are using dependices in your project which are not compatible with the latest version of Kotlin Gradle plugin.
The detailed solution to fix the error “Your project requires a newer version of the Kotlin Gradle plugin.”, is given below:
How to fix “Your project requires a newer version of the Kotlin Gradle plugin.” Error?
To fix the error, you will have to upgrade your kotlin gradle plugin version in your android root project to the latest version 1.7.10 or later. If the error still persists you will have to change your build gradle and gradle wrapper.
To fix the error, “Your project requires a newer version of the Kotlin Gradle plugin.”, you will have to follow the steps mentioned below:
Method 1: Update your kotlin gradle build
To update your kotlin version first follow the path: projectName/android/build.gradle, then you will find ext.kotlin_version.
This is where you will have to update your kotlin version to the latest version which is 1.7.10. Given below is a reference of what you will see when you follow the above path.
buildscript {
ext.kotlin_version = '1.7.10' // Change here
repositories {
google()
jcenter()
}
You can see the newest version of kotlin which you need to use in your project in the link here.
This should fix the error “Your project requires a newer version of the Kotlin Gradle plugin.”.
Method 2: Changing the gradle build and build wrapper
If the above step did not fix your error, you will have to change your grade build and build wrapper
You have to change your build gradle to the below mentioned code :
classpath 'com.android.tools.build:gradle:4.1.0'
You have to change your gradle-wrapper to the below mentioned code :
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip
This should fix the error “Your project requires a newer version of the Kotlin Gradle plugin.”.
Conclusion
To fix the error “Your project requires a newer version of the Kotlin Gradle plugin.”, you will have to have to change your kotlin gradle plugin version in your android root project to the latest version 1.7.10.
If the error still persists you will have to change your build gradle and gradle wrapper.