even after updating the ext.kotlin_version = ‘1.9.23’
I am still getting the same Flutter Fix error
[!] Your project requires a newer version of the Kotlin Gradle plugin.Find the latest version on https://kotlinlang.org/docs/releases.html#release-details, then
update C:project_nameandroidbuild.gradle:
ext.kotlin_version = ‘latest-version’
flutter version 3.19.6
flutter clean
flutter pub get
flutter pub upgrade, etc. tried but none worked
my android/build.gradle file
buildscript {
// ext.kotlin_version = '1.7.10'
ext.kotlin_version = '1.9.23'
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.3.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects {
repositories {
google()
mavenCentral()
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
}
tasks.register("clean", Delete) {
delete rootProject.buildDir
}
my android/app/build.gradle file
plugins {
id "com.android.application"
id "kotlin-android"
id "dev.flutter.flutter-gradle-plugin"
}
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
android {
namespace "com.example.project_name"
compileSdk flutter.compileSdkVersion
ndkVersion flutter.ndkVersion
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
defaultConfig {
applicationId "com.example.project_name"
minSdkVersion 20
targetSdkVersion 31
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
buildTypes {
release {
signingConfig signingConfigs.debug
}
}
}
flutter {
source '../..'
}
dependencies {}
my gradle-wrapper.properties file
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
# distributionUrl=https://services.gradle.org/distributions/gradle-7.6.3-all.zip
distributionUrl=https://services.gradle.org/distributions/gradle-8.7-all.zip
2
Answers
I faced the same problem, but when I gave the latest Kotlin version on android/build.gradle file it worked fine for me.
but, as you face issues after updating the Kotlin version it’s hard to find where wrong as I found Flutter Team changed the code inside the Android portion from Flutter SDK 3.16.
so that, the easiest way would be, first delete the whole Android folder. then run
this will create the Android folder with the newest code.
I hope that it will solve your issue and run your app.
According to the docs the away we deal with gradle plugins has changed. Follow these steps to your project. Basically the
build.gradle
on android level is now like:no
buildScript{...}
anymore.And the
settings.gradle
is now like:You need then especify the latest kotlin version on plugins as the message says. Here’s an exemple of mine:
I had to delete my
.gradle
folder onusers
to the changes apply properly, not just the caches folder inside. Folder’s path/Users/{your_user}/.grade
%USERPROFILE%/.gradle
I’m on Mac so I just ran
rm -rf .gradle
.Next go to your project, run
flutter clean
and finally procede to run the app. This run took a little bit longer here but it works.Hope it helps.