skip to Main Content

I’ve started to get an error starting today saying:

Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.8.0, expected version is 1.6.0.

This error arises after/during I build the .apk binary of my app. I tried the solution explained in 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 but did not succeed. My build.gradle files does not contain such line to add/edit the Kotlin version information. I use Flutter project build with VS Code. Both the build.gradle files (found in android/app/build.gradle and android/build.gradle) does not contain such provision.

Here is the flutter doctor output:

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.24.0, on Ubuntu 22.04.4 LTS 6.5.0-45-generic, locale en_GB.UTF-8)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Chrome - develop for the web
[✓] Linux toolchain - develop for Linux desktop
[✓] Android Studio (version 2023.2)
[✓] VS Code (version 1.92.0)
[✓] Connected device (2 available)
[✓] Network resources

• No issues found!

UPDATE:

Excerpt from my android/settings.gradle file:

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.7.10" apply false
}

The settings.gradle file looks like above, I have no idea which version to set it to. The error message mentions two versions: 1.6.0 and 1.8.0 and here I see 1.7.10 and I don’t understand what to change?

UPDATE 02:

First I tried updating the "org.jetbrains.kotlin.android" version to 1.8.0 and then flutter clean and re-built the app. The same error message appeared. Then I updated the version to 1.6.0. The following error message appeared.

FAILURE: Build failed with an exception.

* Where:
Script '/home/myName/dev/tooling/flutter/packages/flutter_tools/gradle/src/main/kotlin/dependency_version_checker.gradle.kts' line: 375

* What went wrong:
Failed to apply plugin class 'Dependency_version_checker_gradle$FlutterDependencyCheckerPlugin'.
> Error: Your project's Kotlin version (1.6.0) is lower than Flutter's minimum supported version of 1.7.0. Please upgrade your Kotlin version. 
  Alternatively, use the flag "--android-skip-build-dependency-validation" to bypass this check.

  Potential fix: Your project's KGP version is typically defined in the plugins block of the `settings.gradle` file (/home/myName/dev/projects/flutter/MyAndroidApp/MyAndroidApp_v1.0.20__unitPriceDropdownAndTax_plus_FAQs/my_android_app/android/settings.gradle), by a plugin with the id of org.jetbrains.kotlin.android. 
  If you don't see a plugins block, your project was likely created with an older template version, in which case it is most likely defined in the top-level build.gradle file (/home/myName/dev/projects/flutter/MyAndroidApp/MyAndroidApp_v1.0.20__unitPriceDropdownAndTax_plus_FAQs/my_android_app/android/build.gradle) by the ext.kotlin_version property.


* 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 30s
Running Gradle task 'assembleRelease'...                           31.1s
Gradle task assembleRelease failed with exit code 1

So I set the original value of 1.7.10 and flutter clean and built again, this time using the suggested --android-skip-build-dependency-validation flag. The error message appeared again.

UPDATE 03:

This error occurs even building a newly created default demo project.

2

Answers


  1. to change kotlin version go to /android/settings.gradle
    looking for this line

    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.7.10" apply false // change kotlin version here
    }
    

    and change distributionUrl in android/gradle/gradle-wrapper.properties to this

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

    to make it compatible to kotlin version
    https://docs.gradle.org/current/userguide/compatibility.html
    then flutter clean

    Login or Signup to reply.
  2. After scratching my head around this for ages, I finally managed to resolve the issue.

    I installed the Flutter plugin in Android studio and opened the Android folder of my project within Android Studio. From there, open the AGP Upgrade Assistant by going to the top and selecting Tools -> AGP Upgrade Assistant. It should then check your android project and upgrade any necessary file versions to resolve the issue.

    If you get any issues before you get to this stage, try flutter clean as I had an issue with Android studio being unable to perform the Gradle sync before I could open the AGP Upgrade Assistant.

    Hope this helps!

    Link for further information: https://github.com/flutter/flutter/issues/145288

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search