Your project requires a newer version of the Kotlin Gradle plugin. (Android Studio)
Asked Answered
V

21

177

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
Vaasa answered 30/1, 2022 at 21:33 Comment(0)
M
256

You need to change the kotlin version in your android root project, projectName/android/build.gradle, instead of projectName/android/app/build.gradle.

Change the version at ext.kotlin_version line:

buildscript {
    ext.kotlin_version = '1.6.10' // Change here
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:4.1.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

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:

Incompatible classes were found in dependencies. Remove them from the classpath or use '-Xskip-metadata-version-check' to suppress errors
e: /home/user/.gradle/caches/transforms-3/36814238b86d8b6b6f9e4e1263bce879/transformed/jetified-kotlinx-coroutines-core-jvm-1.5.2.jar!/META-INF/kotlinx-coroutines-core.kotlin_module: 
Module was compiled with an incompatible version of Kotlin. 
The binary version of its metadata is 1.5.1, expected version is 1.1.15.

AndroidStudio or IntelliJ Idea will give hint in the project build.gradle file if the kotlin is not the same with the installed kotlin in the IDE.

Note: to see the new versions of Kotlin check this link : https://kotlinlang.org/docs/releases.html#release-details

Malave answered 30/1, 2022 at 22:6 Comment(12)
It works, but how can I identify the kotlin_version based on sdkCallisto
I also changed the distributionUrl in the gradle-wrapper to 7.3.3-all.zipElmiraelmo
@YeasinSheikh: afaik, AndroidStudio or IntelliJ Idea will give warning if the kotlin in build.grade is not the same with the installed kotlin in the IDE.Harmonize
Thanks man. I've been on this issue for 2 days after upgrading my dart and flutter versionsNicholle
Thanks man. I've been on this issue for 2 days after upgrading my dart and flutter versionsNicholle
To update grade : stackoverflow.com/a/69053055Shareeshareholder
To find out the latest version of Kotlin Gradle visit kotlinlang.org/docs/gradle.html#plugin-and-versionsCannibal
But I am using java in flutter and not kotlin, then why I am getting this error?Schoolroom
@Chetan: Some of your dependencies are using kotlin, that's why you got the error.Harmonize
@YeasinSheikh: >Tools->Kotlin->Configure Kotling Plugin UpdateSpinneret
now there are newer versions: check here kotlinlang.org/docs/releases.html#release-detailsSkip
why I'm I getting this error "Unresolved reference: kotlin_version"Layby
A
28

Update your Kotlin to the Latest version. You can see the latest version here

ext.kotlin_version = '1.6.10' //

You can see the latest version of Kotlin from the below link https://kotlinlang.org/docs/gradle.html#plugin-and-versions

enter image description here

Actinometer answered 1/3, 2022 at 9:20 Comment(0)
C
20
  1. Open file : Your Project/android/settings.gradle

  2. Update the line:

    id "org.jetbrains.kotlin.android" version "1.9.23" apply false

    with the most recent version of kotlin

  3. flutter clean then flutter run or invalidate cache

//Update the last line with the lates version of kotlin

plugins {
    id "dev.flutter.flutter-plugin-loader" version "1.0.0"
    id "com.android.application" version "7.3.0" apply false
    id "org.jetbrains.kotlin.android" version "1.9.23" apply false
}
Campo answered 9/3, 2024 at 14:22 Comment(0)
D
13

change build gradle to this :

classpath 'com.android.tools.build:gradle:4.1.0'

and gradle-wrapper to this :

distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip
Disallow answered 30/1, 2022 at 21:52 Comment(0)
F
13

You have to change the kotlin version in your android root, go to

projectName/android/build.gradle

buildscript {
    ext.kotlin_version = '1.7.0'
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:4.1.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

And change the gradle wrapper version to 6.7.1-all or higher in the gradle-wrapper.properties

distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip

Also you can get the lattest version here

Forerunner answered 4/8, 2022 at 6:43 Comment(0)
O
12

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'enter image description here

enter image description here

Oxa answered 10/2, 2022 at 17:24 Comment(2)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Rosanne
In Flutter Got to Andriod/gradle/build.gradle File and UpdaetHouseman
M
8

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 to build.gradle for that dependency and update the kotlin version as other answers here:

ext.kotlin_version = '<latest-version>'

Note 1: you can open build.gradle for the library you want by opening the android module in Android Studio then go to Gradle Scripts from Project tab.

enter image description here

Note 2: you can know which library is causing the error by looking at:

Execution failed for task ':assets_audio_player:compileDebugKotlin'.

It could be more than one library, so after you change kotlin version the error will be changed.

Mickiemickle answered 7/2, 2022 at 12:36 Comment(4)
how to solve it I updated to latest version but still getting the errorExcurved
@RajaEhtisham Can you write the error line as in note 2 in my answer?Mickiemickle
God Bless you, you saved my day, it helped me to solve this problemKahn
I just commented ext.kotlin_version = <> in the libraries gradle, and automatically it will use the one I set in my app's gradle.Hynda
C
8

change kotlin version to ext.kotlin_version = '1.8.21' inside android/build.gradle , it fixes your problem.

check all versions here Find Latest Kotlin Version

Chink answered 15/5, 2023 at 9:36 Comment(2)
I created a new Flutter 3.10 project. It had the Kotlin version as 1.7.10. So that's what I went with.Turmoil
i did not work for me. i edited this line to use the latest version, still same errorSpecialism
A
7

Change ext.kotlin_version on projectName/android/build.gradle

buildscript {
   ext.kotlin_version = '1.8.22' //latest version
   repositories {
      google()
      mavenCentral()
   }

   dependencies {
      classpath 'com.android.tools.build:gradle:7.1.2'
      classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
   }
}

You can get the "latest kotlin_version" using the below link https://kotlinlang.org/docs/gradle-configure-project.html#apply-the-plugin

Angelicangelica answered 18/6, 2023 at 12:59 Comment(0)
L
5
  • Change the build gradle version to 4.1.0 or higher in the project-level build.gradle file:

    classpath 'com.android.tools.build:gradle:4.1.0'
    
  • Change the gradle wrapper version to 6.7-all or higher in the gradle-wrapper.properties file:

    distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip
    
  • Change the ext.kotlin_version to 1.6.10 or higher in the project level build.gradle file:

    buildscript {
      ext.kotlin_version = '1.6.10' // Change like this
      repositories {
          google()
          jcenter()
      }
    
      dependencies {
          classpath 'com.android.tools.build:gradle:4.1.0'
          classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
      }
    }
    
Lambda answered 1/5, 2022 at 14:19 Comment(0)
G
5

1- First change ext.kotlin_version on projectName/android/build.gradle

buildscript {
    ext.kotlin_version = '1.6.10'
}

2- Second change build gradle to this :

distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip
Gastroenteritis answered 6/6, 2022 at 13:28 Comment(0)
U
5

After spending so many hours I have found the exact version of gradle for this issue.

  1. Clear gradle cache from home directory <YOUR HOME DIRECTORY>/.gradle/caches
  2. Delete folder in your project <YOUR PROJECT DIRECTORY>/android/.gradle
  3. Set latest version of gradle in android/build.gradle. At this moment its 1.9.10. So my build.gradle file looks like enter image description here
  4. Update gradle-wrapper.properties with below distribtutionUrl distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip
  5. flutter clean
  6. flutter pub get
  7. Build/Run your project now.
Ubiquitarian answered 4/10, 2023 at 4:19 Comment(0)
H
2

enter image description here In Flutter Project Navigate to Android/gradle/build.gradle File and Update Kotline Version to New Version

Houseman answered 11/6, 2023 at 12:36 Comment(0)
L
2

This is latest version Works for me.

buildscript {
ext.kotlin_version = '1.8.21' 
repositories {
    google()
    mavenCentral()
}

dependencies {
    classpath 'com.android.tools.build:gradle:7.3.0'
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Langdon answered 20/12, 2023 at 8:50 Comment(0)
U
2

Here's my experience as a Windows user.

I had this error, when trying to build with flutter build apk --split-per-abi:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:packageRelease'.
> java.io.IOException: Unable to delete directory 'D:\Users\mikyll\flutter_application\build\app\outputs\apk\release'
    Failed to delete some children. This might happen because a process has files open or has its working directory set in the target directory.
    - D:\Users\mikyll\flutter_application\build\app\outputs\apk\release\app-arm64-v8a-release.apk
    - D:\Users\mikyll\flutter_application\build\app\outputs\apk\release\app-armeabi-v7a-release.apk
    - D:\Users\mikyll\flutter_application\build\app\outputs\apk\release\app-x86_64-release.apk

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 1m 56s
Running Gradle task 'assembleRelease'...                          117,7s

┌─ Flutter Fix ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ [!] 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 D:\Users\mikyll\flutter_application\android\build.gradle: │
│ ext.kotlin_version = '<latest-version>'                                                                                                                                                         │
└─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
Gradle task assembleRelease failed with exit code 1

I updated ext.kotlin_version to the latest (1.9.22 when I'm writing this answer), but it kept failing.

As the error is suggesting, the problem was the OpenJDK Platform binary process was frozen for some reason and flutter build could not replace the previous built APKs with the new one, since they were busy (open in that process).

Solution

I solved by terminating OpenJDK Platform binary process from task manager, deleting the old APK releases, and the next build went straight forward

Usual answered 17/1, 2024 at 23:56 Comment(0)
T
1

A huge solution for updating the Android application is to delete the android folder and then run this:

flutter create .

Note: you can also run flutter upgrade command to upgrade flutter first.

Taxeme answered 11/3, 2023 at 0:44 Comment(1)
this need only first project. Otherwise, so many configuration issue across with usUnderestimate
V
1

This method in latest versions works

Directory

  • android/build.gradle
    buildscript {
     ext.kotlin_version = '1.5.31' // Put this number
     repositories {
        google()
        jcenter()
     }
   }

FAQ https://docs.flutter.dev/release/breaking-changes/kotlin-version

Vasiliu answered 12/3, 2023 at 23:11 Comment(0)
G
0

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.

Granville answered 27/4, 2022 at 20:19 Comment(1)
This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From ReviewAlsatian
T
0

You can reach the latest version from here.

Thigmotaxis answered 13/1, 2023 at 2:10 Comment(0)
F
0

It is always worth checking that you are trying to build the right Flutter project. I ran into this issue recently only to discover that I had accidentally switched to an older version of the project - another folder - which I had replicated when I made a long delayed flutter pubgrade

Frawley answered 24/7, 2023 at 5:26 Comment(0)
C
-2

Just restart the IDE. Worked for me.

I was using VS Code.

Colpitis answered 9/11, 2023 at 12:19 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.