skip to Main Content

I’m developing a Flutter application in Android Studio. After upgrading the Flutter version from around 2.8 to 3.19.5, the Android build on a physical device no longer works.

The error is as follows:

    e: /Users/shun/.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: /Users/shun/.gradle/caches/transforms-3/b268270c5f07ae84179bbcf92aab4c93/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: /Users/shun/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.9.24/9928532f12c66ad816a625b3f9984f8368ca6d2b/kotlin-stdlib-1.9.24.jar!/META-INF/kotlin-stdlib.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.9.0, expected version is 1.6.0.
e: /Users/shun/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.9.24/9928532f12c66ad816a625b3f9984f8368ca6d2b/kotlin-stdlib-1.9.24.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.9.0, expected version is 1.6.0.
e: /Users/shun/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.9.24/9928532f12c66ad816a625b3f9984f8368ca6d2b/kotlin-stdlib-1.9.24.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.9.0, expected version is 1.6.0.

┌─ 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 /Users/shun/Downloads/workspace/mirre/android/build.gradle: │
│ ext.kotlin_version = '<latest-version>'                                                                                                                       │
└─────────────────────────────────────────────────────────────────────────

android/build.gradle file with:

 buildscript {
        ext.kotlin_version = '1.9.24'
        repositories {
            google()
            mavenCentral()
        }
    
        dependencies {
            classpath 'com.android.tools.build:gradle:7.1.2'
            classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
            classpath 'com.google.gms:google-services:4.3.8'
            classpath 'com.google.firebase:perf-plugin:1.4.1'
        }
    }

flutter doctor is as follows:

[✓] Flutter (Channel stable, 3.19.5, on macOS 14.5 23F79 darwin-arm64 (Rosetta), locale ja-JP)
    • Flutter version 3.19.5 on channel stable at /Users/shun/Downloads/workspace/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 300451adae (9 weeks ago), 2024-03-27 21:54:07 -0500
    • Engine revision e76c956498
    • Dart version 3.3.3
    • DevTools version 2.31.1

[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.0-rc1)
    • Android SDK at /Users/shun/Library/Android/sdk
    • Platform android-34-ext8, build-tools 35.0.0-rc1
    • ANDROID_HOME = /Users/shun/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.10+0-17.0.10b1087.21-11572160)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.4)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15F31d
    • CocoaPods version 1.15.0

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2023.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.10+0-17.0.10b1087.21-11572160)

[✓] VS Code (version 1.89.1)
    • VS Code at /Users/shun/Downloads/Visual Studio Code.app/Contents
    • Flutter extension version 3.88.0

[✓] Connected device (6 available)
    • M2101K6G (mobile)      • 63397ca9                             • android-arm64  • Android 13 (API 33)
    • shun's iPad (mobile)     • 00008030-001944DE3682202E            • ios            • iOS 17.4.1 21E236
    • shun's (mobile)          • 00008120-000A308A1103C01E            • ios            • iOS 17.4.1 21E236
    • iPhone 15 Pro (mobile) • A21A87ED-90BB-4062-B92F-D76D7F68ED0C • ios            • com.apple.CoreSimulator.SimRuntime.iOS-17-5 (simulator)
    • macOS (desktop)        • macos                                • darwin-arm64   • macOS 14.5 23F79 darwin-arm64 (Rosetta)
    • Chrome (web)           • chrome                               • web-javascript • Google Chrome 125.0.6422.78

[✓] Network resources
    • All expected network resources are available.

• No issues found!

Articles suggest that changing the build.gradle file should resolve the issue, but I’m not using Kotlin version 1.6.0 anywhere in my project, which is causing confusion.

I tried change the Kotlin version in android/ build.gradle,,,

but,it couldn’t read the project.

3

Answers


  1. I had the same problem a while ago, What I have done is set Kotlin version from

    ext.kotlin_version = '1.9.10'
    

    to

    ext.kotlin_version = '1.6.0'
    

    and I have also update the target for my android devices <project_dir>/android/app/build.gradle to:

    android {
        compileSdkVersion 34
        defaultConfig {
            minSdkVersion 23 
            targetSdkVersion 34
            ...
        }
    }
    

    Explanation:

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

    This error usually occurs when there’s a mismatch between the Kotlin compiler version used to compile a module and the version expected by the Kotlin runtime in your Flutter project.

    The expected version is the Kotlin for kotlin-gradle-plugin and The binary version is for what is downloaded for com.android.tools.build:gradle

    after doing this remove Invalidate caches and restart IDE or flutter clean and flutter run.

    Login or Signup to reply.
  2. I would recommend you to check this link Flutter Gradle Plugin.
    Follow the steps mentioned and run flutter clean once, should work without any issues.

    Login or Signup to reply.
  3. I had the same problem a while ago I’ve went to kotlin gradle versions below is the link

    [Kotlin versions link][1]
    [1]: https://kotlinlang.org/docs/releases.html

    To build a Flutter app for Android, Kotlin 1.5.31 or greater is required.

    You can change version of Kotlin under build.gradle file and the do restart your IDE.

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