skip to Main Content

I recently replaced my laptop, and I want to build apps with Flutter on it. The new laptop is running Windows 11. I have installed Android Studio and Flutter, and the software versions are as follows:

Android Studio:

  • Koala 2024.1.1 // Patch 2
  • Runtime version: 17.0.11+0–11852314 amd64
  • VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o

Flutter:

  • Flutter 3.24.1 • channel stable • GitHub Repository
  • Framework • revision 5874a72aa4 (13 days ago) • 2024-08-20 16:46:00 -0500
  • Engine • revision c9b9d5780d
  • Tools • Dart 3.5.1 • DevTools 2.37.2

The installation was successful, and there were no errors when I ran

flutter doctor:

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.24.1, on Microsoft Windows [version] 10.0.22631.4037], locale fr-FR)
[✓] Windows Version (Installed version of Windows is version 10 or higher)
[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.0)
[✓] Chrome - develop for the web
[✓] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.11.2)
[✓] Android Studio (version 2024.1)
[✓] VS Code (version 1.92.2)
[✓] Connected device (3 available)
[✓] Network resources
• No issues found!

However, when I run the base project or any project in debug mode, no problems are detected. But in release mode, I encounter the following issue:

C:UsersuserDownloadsceciestuntest>flutter build apk
Warning: This version only understands SDK XML versions up to 3 but an SDK XML file of version 4 was encountered. This can happen if you use versions of Android Studio and the command-line tools that were released at different times.
Running Gradle task 'assembleRelease'...                               Font asset "MaterialIcons-Regular.otf" was tree-shaken, reducing it from 1645184 to 1384 bytes (99.9% reduction). Tree-shaking can be disabled by providing the --no-tree-shake-icons flag when building your app.
e: C:/Users/user/.gradle/caches/transforms-3/c683cde5b1f5377825fe27da54e1b718/transformed/fragment-1.7.1/jars/classes.jar!/META-INF/fragment_release.kotlin_module: 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.
e: C:/Users/user/.gradle/caches/transforms-3/4b07bb875192e8c29c9b76677237c5c8/transformed/jetified-activity-1.8.1/jars/classes.jar!/META-INF/activity_release.kotlin_module: 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.
e: C:/Users/user/.gradle/caches/transforms-3/455c428e62a6dd75da98c7152f7af462/transformed/jetified-lifecycle-livedata-core-ktx-2.7.0/jars/classes.jar!/META-INF/lifecycle-livedata-core-ktx_release.kotlin_module: 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.
e: C:/Users/user/.gradle/caches/transforms-3/0313b4099446464f98d0df0606c58c95/transformed/lifecycle-livedata-2.7.0/jars/classes.jar!/META-INF/lifecycle-livedata_release.kotlin_module: 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.
e: C:/Users/user/.gradle/caches/transforms-3/2e94595ca22e3aadcdebdc547820608c/transformed/lifecycle-viewmodel-2.7.0/jars/classes.jar!/META-INF/lifecycle-viewmodel_release.kotlin_module: 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.
e: C:/Users/user/.gradle/caches/transforms-3/ce9e6112a0f9c5113844bb49506e7a06/transformed/lifecycle-livedata-core-2.7.0/jars/classes.jar!/META-INF/lifecycle-livedata-core_release.kotlin_module: 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.
e: C:/Users/user/.gradle/caches/transforms-3/6e7c2231d2ac9b957ecfe9d432e59ed2/transformed/jetified-lifecycle-viewmodel-savedstate-2.7.0/jars/classes.jar!/META-INF/lifecycle-viewmodel-savedstate_release.kotlin_module: 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.
e: C:/Users/user/.gradle/caches/transforms-3/740c93e8e1043856a6b7cb15a7eaa9f0/transformed/jetified-core-ktx-1.13.1/jars/classes.jar!/META-INF/core-ktx_release.kotlin_module: 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.
e: C:/Users/user/.gradle/caches/transforms-3/fac84cd5ecf1ec88a8c98571217c9350/transformed/core-1.13.1/jars/classes.jar!/META-INF/core_release.kotlin_module: 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.
e: C:/Users/user/.gradle/caches/transforms-3/98474e5913354eaede53aaa879a4dd8b/transformed/lifecycle-runtime-2.7.0/jars/classes.jar!/META-INF/lifecycle-runtime_release.kotlin_module: 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.
e: C:/Users/user/.gradle/caches/transforms-3/d674cd90e13def17f77b3f8010d35e09/transformed/jetified-lifecycle-process-2.7.0/jars/classes.jar!/META-INF/lifecycle-process_release.kotlin_module: 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.
e: C:/Users/user/.gradle/caches/modules-2/files-2.1/androidx.lifecycle/lifecycle-common/2.7.0/85334205d65cca70ed0109c3acbd29e22a2d9cb1/lifecycle-common-2.7.0.jar!/META-INF/lifecycle-common.kotlin_module: 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.
e: C:/Users/user/.gradle/caches/transforms-3/5292c4072ce6d2ab49b0e25db445cdfe/transformed/jetified-window-java-1.2.0/jars/classes.jar!/META-INF/window-java_release.kotlin_module: 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.
e: C:/Users/user/.gradle/caches/transforms-3/d47b1192960df52846144d82ac9e1d6f/transformed/jetified-window-1.2.0/jars/classes.jar!/META-INF/window_release.kotlin_module: 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.
e: C:/Users/user/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlinx/kotlinx-coroutines-core-jvm/1.7.1/63a0779cf668e2a47d13fda7c3b0c4f8dc7762f4/kotlinx-coroutines-core-jvm-1.7.1.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.8.0, expected version is 1.6.0.
e: C:/Users/user/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlinx/kotlinx-coroutines-android/1.7.1/c2d86b569f10b7fc7e28d3f50c0eed97897d77a7/kotlinx-coroutines-android-1.7.1.jar!/META-INF/kotlinx-coroutines-android.kotlin_module: 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.
e: C:/Users/user/.gradle/caches/transforms-3/aadceac8ee0316c01a9163bad1a5e0ed/transformed/jetified-savedstate-1.2.1/jars/classes.jar!/META-INF/savedstate_release.kotlin_module: 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.
e: C:/Users/user/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.8.22/636bf8b320e7627482771bbac9ed7246773c02bd/kotlin-stdlib-1.8.22.jar!/META-INF/kotlin-stdlib-jdk7.kotlin_module: 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.
e: C:/Users/user/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.8.22/636bf8b320e7627482771bbac9ed7246773c02bd/kotlin-stdlib-1.8.22.jar!/META-INF/kotlin-stdlib.kotlin_module: 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.
e: C:/Users/user/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.8.22/636bf8b320e7627482771bbac9ed7246773c02bd/kotlin-stdlib-1.8.22.jar!/META-INF/kotlin-stdlib-jdk8.kotlin_module: 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.
e: C:/Users/user/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-common/1.8.22/1a8e3601703ae14bb58757ea6b2d8e8e5935a586/kotlin-stdlib-common-1.8.22.jar!/META-INF/kotlin-stdlib-common.kotlin_module: 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.

I have tried to install other versions of Flutter and Android Studio, but I still have the same issues. I have also tried many solutions found on the internet, but none of them worked. Most of them involved modifying the Gradle configuration, but it didn’t help.

I really hope someone can assist me. Thanks in advance for your help!

2

Answers


  1. What version of Android studio did you have on your old computer? Was it working properly? I have exactly the versions you describe and I have the same output as well.

    Login or Signup to reply.
  2. I finally managed to solve the problem, I found 2 ways, each one depends on the needs of your project.

    Why do I get this error?

    the error indicates that you have installed in your android studio the kotlin version 1.8.0, but by default a new flutter project is configured to use version 1.6.0.

    solution 1, configure flutter to the expected kotlin version:

    To do this, first you have to update the corresponding plugins in your settings.gradle file.
    in my case by default I had the following:

    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
    }
    

    and change it to:

    plugins {
        id “dev.flutter.flutter-plugin-loader” version “1.0.0”
        id “com.android.application” version “8.0.0” apply false
        id “org.jetbrains.kotlin.android” version “1.8.0” apply false
    }
    

    it is important that you update both kotlin and gradle plugins since kotlin version 1.8.0 is at least compatible with gradle version 8.0.0.

    then it is necessary that in your gradle-wrapper.properties file you update in the same way the gradle , in my case I updated

    from

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

    to:

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

    once you do that check what version of openjdk you have installed, in my case the android studio has version 17 and is the one I use, so I had to change it in my android/app/build.gradle file:

    from:

    compileOptions {
            sourceCompatibility = JavaVersion.VERSION_1_8
            targetCompatibility = JavaVersion.VERSION_1_8
        }
    

    to:

            sourceCompatibility = JavaVersion.VERSION_17
            targetCompatibility = JavaVersion.VERSION_17
        }
    

    Finally, to make sure that the campaign takes effect, you must do the following to delete cache:

    1.- Run the comand flutter clean

    2.- Go to the root directory of your app ,move to the android folder and delete .gradle folder

    3.- additionally you can go to the error directory C:Usersuser.gradle and delete the caches folder

    after doing all of the above just load the packages again with flutter pub get and try to compile your application, it should work.

    Solution 2, change te flutter version

    This should be easier

    First Change the flutter version to 3.22.2

    After that you must to clean all cache in your project

    1.- Run the comand flutter clean

    2.- Go to the root directory of your app ,move to the android folder and delete .gradle folder

    3.- additionally you can go to the error directory C:Usersuser.gradle and delete the caches folder

    4.- get the packages again and try to compile again,it should works.

    Each of the solutions depends on your application, this is because the first solution involves upgrading kotlin and gradle to version 8 in your project, the problem is that many libraries work with version 7 of graddle and if you use the first solution and some of your dependencies do not yet support version 8 of gradle, you will have problems when compiling, that’s what happened to me, a main library of my project does not support gradle 8 so going back to version 3.22.2 of flutter worked for me.

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