I’ve just updated my flutter project packages to be null-safety compliant and now Android Studio wants me to update my project to use the latest version of Kotling Gradle Plugin. Can’t see where to change this though. I have tried to change "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
into "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.6.10"
but this has no effect.
My build.grade
-file looks like this:
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}
android {
compileSdkVersion 31
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
lintOptions {
disable 'InvalidPackage'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "*********"
minSdkVersion 30
targetSdkVersion 30
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
signingConfigs {
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
storePassword keystoreProperties['storePassword']
}
}
buildTypes {
release {
signingConfig signingConfigs.release
}
}
}
flutter {
source '../..'
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
implementation 'com.google.firebase:firebase-analytics:17.2.2'
}
apply plugin: 'com.google.gms.google-services'
Build output:
BUILD FAILED in 8s
[!] 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
12
Answers
change build gradle to this :
and gradle-wrapper to this :
You need to change the kotlin version in your android root project,
projectName/android/build.gradle
, instead ofprojectName/android/app/build.gradle
.Change the version at
ext.kotlin_version
line:UPDATE
The above solution will also works if your android part of the project is using java where the dependencies are using kotlin and you’ve encountered the following error:
AndroidStudio or IntelliJ Idea will give hint in the project
build.grade
file if the kotlin is not the same with the installed kotlin in the IDE.In my case, I don’t use kotlin in my flutter project, but some of my dependencies use it (It was
assets_audio_player
for me), so I had to go tobuild.gradle
for that dependency and update the kotlin version as other answers here:Note 1: you can open
build.gradle
for the library you want by opening the android module in Android Studio then go toGradle Scripts
from Project tab.Note 2: you can know which library is causing the error by looking at:
It could be more than one library, so after you change kotlin version the error will be changed.
I Update Flutter to 2.10.1
and I found All My Project Has Same Error
in app /build.gradl
you change to ext.kotlin_version = ‘1.6.10’
Update your Kotlin to the Latest version. You can see the latest version here
You can see the latest version of Kotlin from the below link
https://kotlinlang.org/docs/gradle.html#plugin-and-versions
Maybe anyone else is stumbling across an issue I had after upgrading flutter:
If you use flutter together with aws_amplify you have to also upgrade amplify. This is a issue I had with the same error message.
Change the build gradle version to 4.1.0 or higher in the project-level
build.gradle
file:Change the gradle wrapper version to 6.7-all or higher in the
gradle-wrapper.properties
file:Change the
ext.kotlin_version
to 1.6.10 or higher in the project levelbuild.gradle
file:1- First change
ext.kotlin_version
onprojectName/android/build.gradle
2- Second change build gradle to this :
You have to change the
kotlin version
in yourandroid
root, go toAnd change the gradle wrapper version to 6.7.1-all or higher in the
gradle-wrapper.properties
Also you can get the lattest version here
You can reach the latest version from here.
A huge solution for updating the Android application is to delete the android folder and then run this:
Note: you can also run
flutter upgrade
command to upgrade flutter first.This method in latest versions works
Directory
FAQ
https://docs.flutter.dev/release/breaking-changes/kotlin-version