Skip to content

Flutter Android build fails due to outdated Kotlin plugin (1.8.0) incompatible with Kotlin 2.x dependencies #179253

Description

@Turskyi

Steps to reproduce

  1. Create a new Flutter project (or open an existing one).
  2. In the android/ directory:
    • Update Android Gradle Plugin to the latest stable version.
    • Update Gradle wrapper to the latest version.
    • Set Kotlin to 2.2.21 (latest at the moment).
  3. Add
dependencies {
    implementation 'com.google.firebase:firebase-crashlytics:20.0.3'
    implementation 'com.google.firebase:firebase-analytics:23.0.0'
}
  1. Add several Flutter plugins that include Android native code, e.g.:
    • flutter_email_sender
    • home_widget
    • package_info_plus
    • geolocator
    • workmanager
  2. Run flutter pub get.
  3. Try to build the Android app using:
flutter build apk
  1. The build fails with a long list of errors similar to:
Incompatible classes were found in dependencies. 
Module was compiled with an incompatible version of Kotlin. 
The binary version of its metadata is 2.2.0, expected version is 1.8.0.

Expected results

The project should build successfully on Android without any Kotlin metadata–version errors. Specifically:
• Gradle should resolve all Android and Flutter plugin dependencies without reporting incompatible Kotlin metadata.
• Kotlin stdlib should match the Kotlin version declared in the project (e.g., 2.x.x or the Flutter-managed version).
• Third-party Flutter plugins such as flutter_email_sender, home_widget, package_info_plus, geolocator, and Firebase libraries should compile without throwing class incompatibility errors.
• The build should finish normally with no errors like:
• “Module was compiled with an incompatible version of Kotlin”
• “Unresolved reference: ArrayList”
• “Class ‘kotlin.Unit’ was compiled with an incompatible version of Kotlin”
• Running flutter build apk or building from Android Studio should produce a valid APK/AAB.

Actual results

The Android build fails during Kotlin compilation with errors indicating a metadata version mismatch between Flutter’s pinned Kotlin plugin (1.8.0) and dependencies compiled with Kotlin 2.x. The build stops with messages such as:

Incompatible classes were found in dependencies.
Module was compiled with an incompatible version of Kotlin.
The binary version of its metadata is 2.2.0, expected version is 1.8.0.

Additional related errors appear, for example:

Unresolved reference: ArrayList
Unresolved reference: Unit
Cannot access class 'kotlin.Unit'
Incompatible ABI version detected

The app does not compile until the Kotlin Gradle plugin inside the Flutter SDK is manually changed from 1.8.0 to 2.2.x, which is not a valid or stable workaround because the file is inside Flutter’s cached toolchain.

Misleading Flutter Fix suggestion

When the build fails, Flutter suggests the following fix:

─ 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 the │
│ version number of the plugin with id "org.jetbrains.kotlin.android" in the plugins block of │
│ /<path_to_project>/android/settings.gradle. │
│ │
│ Alternatively (if your project was created before Flutter 3.19), update │
│ /<path_to_project>/android/build.gradle │
│ ext.kotlin_version = '' │
└───────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
This suggestion is incorrect and does not resolve the issue, because:
• My project is already using the latest Kotlin (2.2.x) everywhere (Gradle plugin, buildscript, gradle.properties).
• The error is caused by Flutter tools internally pinning the Kotlin version to 1.8.0:

implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.0")
•	As a result, applying the suggested fix does not resolve the problem and can lead to harder-to-diagnose incompatibilities.

Flutter Fix therefore points developers toward a solution that not only doesn’t help, but can worsen the mismatched Kotlin metadata error.

Code sample

Code sample
// android/app/build.gradle (snippet)
plugins {
    id "com.android.application"
    id "kotlin-android"
    id "dev.flutter.flutter-gradle-plugin"
    id "com.google.gms.google-services"
    id "com.google.firebase.crashlytics"
}

dependencies {
    implementation "com.google.firebase:firebase-crashlytics:20.0.3"
    implementation "com.google.firebase:firebase-analytics:23.0.0"
}
# android/gradle.properties
org.gradle.jvmargs=-Xmx8G -XX:MaxMetaspaceSize=4G -XX:ReservedCodeCacheSize=512m -XX:+HeapDumpOnOutOfMemoryError
android.useAndroidX=true
android.enableJetifier=true
android.nonTransitiveRClass=false
android.nonFinalResIds=false
kotlin.code.style=official
kotlin.version=2.2.21
// android/build.gradle
buildscript {
    ext {
        kotlin_version = "2.2.21"
    }

    repositories {
        google()
        mavenCentral()
    }

    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}
// android/settings.gradle (snippet)
pluginManagement {
    plugins {
        id "dev.flutter.flutter-gradle-plugin" version "1.0.0" apply false
        id "org.jetbrains.kotlin.android" version "2.2.21"
        id "com.google.gms.google-services" version "4.4.4"
        id "com.google.firebase.crashlytics" version "3.0.6"
    }
}
# android/gradle/wrapper/gradle-wrapper.properties
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-all.zip

Screenshots or Video

Screenshots / Video demonstration Image Image

Logs

Logs
Launching lib/main.dart on Pixel 6 in debug mode...
Running Gradle task 'assembleDebug'...
e: Incompatible classes were found in dependencies. Remove them from the classpath or use '-Xskip-metadata-version-check' to suppress errors
e: file:///Users/dmytro/.gradle/caches/8.14.3/transforms/bb865196f62611e9b2493b8d5705f90b/transformed/jetified-kotlin-stdlib-2.2.0.jar!/META-INF/kotlin-stdlib-jdk7.kotlin_moduleModule was compiled with an incompatible version of Kotlin. The binary version of its metadata is 2.2.0, expected version is 1.8.0.
..other similar errors...
The class is loaded from /Users/dmytro/.gradle/caches/8.14.3/transforms/163fcc37b5abf253a041a32973c354cb/transformed/jetified-kotlin-stdlib-2.1.20.jar!/kotlin/Unit.class

FAILURE: Build completed with 3 failures.

1: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':package_info_plus:compileDebugKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction
   > Compilation error. See log for more details

* 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.
==============================================================================

2: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':flutter_email_sender:compileDebugKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction
   > Compilation error. See log for more details

* 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.
==============================================================================

3: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':home_widget:compileDebugKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction
   > Compilation error. See log for more details

* 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 5s
┌─ 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 the                                                                                       │
│ version number of the plugin with id "org.jetbrains.kotlin.android" in the plugins block of      │
<path-to-project>/android │
│ /settings.gradle.                                                                                │
│                                                                                                  │
│ Alternatively (if your project was created before Flutter 3.19), update                          │
│ /<path-to-project>/android │
│ /build.gradle                                                                                    │
│ ext.kotlin_version = '<latest-version>'                                                          │
└──────────────────────────────────────────────────────────────────────────────────────────────────┘
Error: Gradle task assembleDebug failed with exit code 1

Flutter Doctor output

Doctor output
flutter doctor -v
[✓] Flutter (Channel stable, 3.38.3, on macOS 26.1 25B78 darwin-arm64, locale uk-CA) [1 001ms]
    • Flutter version 3.38.3 on channel stable at /Users/<name>/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 19074d12f7 (10 days ago), 2025-11-20 17:53:13 -0500
    • Engine revision 13e658725d
    • Dart version 3.10.1
    • DevTools version 2.51.1
    • Feature flags: enable-web, enable-linux-desktop, enable-macos-desktop, enable-windows-desktop, enable-android, enable-ios, cli-animations, enable-native-assets, omit-legacy-version-file,
      enable-lldb-debugging

[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.0) [1 772ms]
    • Android SDK at /Users/<name>/Library/Android/sdk
    • Emulator version 36.2.12.0 (build_id 14214601) (CL:N/A)
    • Platform android-36-ext18, build-tools 35.0.0
    • ANDROID_SDK_ROOT = /Users/<name>/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
      This is the JDK bundled with the latest Android Studio installation on this machine.
      To manually set the JDK path, use: `flutter config --jdk-dir="path/to/jdk"`.
    • Java version OpenJDK Runtime Environment (build 21.0.8+-14196175-b1038.72)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 26.1.1) [1 439ms]
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 17B100
    • CocoaPods version 1.16.2

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

[✓] Connected device (3 available) [6,0s]
    • iPad (wireless) (mobile) • 00008020-001E6D690168402E • ios            • iOS 26.1 23B85
    • macOS (desktop)                                • macos                     • darwin-arm64   • macOS 26.1 25B78 darwin-arm64
    • Chrome (web)                                   • chrome                    • web-javascript • Google Chrome 142.0.7444.176

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

• No issues found!

Metadata

Metadata

Assignees

No one assigned

    Labels

    r: duplicateIssue is closed as a duplicate of an existing issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions