Description:
I’m facing an issue with Kotlin version mismatching the SDK versions in my Flutter project. Despite trying different versions of Kotlin and the Android Gradle plugin, I’m encountering errors when building or running the project. The issue arises due to compatibility conflicts between the specified Kotlin version and the Android Gradle plugin version.
Steps Taken:
Created a new Flutter project.
Added dependencies for google_maps_flutter and location in pubspec.yaml.
Updated the Kotlin version and Android Gradle plugin version in the build.gradle files.
Ran flutter pub get to fetch the dependencies.
Attempted to run the app using flutter run, but encountered version mismatch errors.
Project-Level build.gradle
:
buildscript {
ext.kotlin_version = '1.5.20' // Tried with different versions
repositories {
google()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:7.0.0" // Tried with different versions
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects {
repositories {
google()
mavenCentral()
}
configurations.all {
resolutionStrategy {
force "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
}
rootProject.buildDir = "../build"
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(":app")
}
tasks.register("clean", Delete) {
delete rootProject.buildDir
}
Pubspec.yamal
environment:
sdk: ">=2.12.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
flutter_polyline_points: ^1.0.0
google_maps_flutter: ^2.1.7
geolocator: ^9.0.1
location: ^4.4.0
Error Message
The specified Kotlin version 1.5.20 is not compatible with the Android Gradle plugin version 7.0.0.
Please use Kotlin version 1.5.31 or later.
Despite these efforts, the issue remains unresolved. I would greatly appreciate any guidance on how to resolve this version mismatch and successfully run my Flutter project with the required Kotlin and SDK versions.
Sethu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.