43

I'm facing this nasty error when trying to compile my Flutter App into an Android simulator. Here is the error log (is too long to paste it entirely):

aunching lib/main.dart on sdk gphone x86 in debug mode... Running Gradle task 'assembleDebug'... Note: Some input files use or override a deprecated API. Note: Recompile with -Xlint:deprecation for details. e: Incompatible classes were found in dependencies. Remove them from the classpath or use '-Xskip-metadata-version-check' to suppress errors e: /Users/reinier/.gradle/caches/transforms-2/files-2.1/24fa3aa8d2270e5eb067bbe36e9b7563/jetified-kotlin-stdlib-1.5.10.jar!/META-INF/kotlin-stdlib.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. e: /Users/reinier/.gradle/caches/transforms-2/files-2.1/4d4ccf1034ba5937e6e7ba3aa34d2661/jetified-core-ktx-1.6.0-beta02-api.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.5.1, expected version is 1.1.15. e: /Users/reinier/.gradle/caches/transforms-2/files-2.1/77bab1911042ab2c6d5cc0b2e2ee053c/jetified-kotlin-stdlib-common-1.5.10.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.5.1, expected version is 1.1.15. e: /Users/reinier/Developer/flutter/.pub-cache/hosted/pub.dartlang.org/audioplayers-0.18.3/android/src/main/kotlin/xyz/luan/audioplayers/AudioplayersPlugin.kt: (18, 32): Unresolved reference: mutableMapOf e: /Users/reinier/Developer/flutter/.pub-cache/hosted/pub.dartlang.org/audioplayers-0.18.3/android/src/main/kotlin/xyz/luan/audioplayers/AudioplayersPlugin.kt: (25, 9): Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.5.1, expected version is 1.1.15.

. . . . .

e: /Users/reinier/Developer/flutter/.pub-cache/hosted/pub.dartlang.org/audioplayers-0.18.3/android/src/main/kotlin/xyz/luan/audioplayers/WrappedSoundPool.kt: (235, 30): Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.5.1, expected version is 1.1.15. The class is loaded from /Users/reinier/.gradle/caches/transforms-2/files-2.1/24fa3aa8d2270e5eb067bbe36e9b7563/jetified-kotlin-stdlib-1.5.10.jar!/kotlin/Unit.class

FAILURE: Build failed with an exception.

  • What went wrong: Execution failed for task ':audioplayers:compileDebugKotlin'.

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 21s Exception: Gradle task assembleDebug failed with exit code 1

  1. I already tried changing "minSdkVersion 16" to "minSdkVersion 23" at android/app/build.gradle:38 and is not working.
  2. Tried using the version 0.17.0 of audioplayers and the same, not working.
  3. Tried using the version ^0.10.0 of audioplayers and nothing.
  4. Tried doing the previos steps and then executing on the terminal: flutter clean & flutter pub get... and nothing.
  5. I already updated the Flutter SDK and nothing. Still not working for Android.

It compiles perfectly on an IOS simulator. This error has emerged several times after each audioplayers package update. I'm using compileSdkVersion 30 on Android Studio 4.2.1

This is my pubspec.yaml file:

name: feeddy_flutter
description: A multi screen foods listing Flutter app

publish_to: 'none' # Remove this line if you wish to publish to pub.dev

version: 1.0.0+1

environment:
  sdk: ">=2.7.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter

  cupertino_icons: ^1.0.2
  intl: ^0.17.0
  uuid: ^3.0.4
  currency_text_input_formatter: ^2.0.1
  date_time_picker: ^2.0.0
  rflutter_alert: ^2.0.2
  faker: ^1.3.0
  fl_chart: ^0.35.0
  provider: ^5.0.0
  tinycolor: ^1.0.3
  font_awesome_flutter: ^9.0.0
  audioplayers: ^0.18.3
  empty_widget: ^0.0.2
  splashscreen: ^1.3.5
  native_device_orientation: ^1.0.0
  sqflite: ^2.0.0+3
  flutter_switch: ^0.3.1
  flutter_colorpicker: ^0.4.0
  enum_to_string: ^2.0.1
  humanizer: ^0.0.2
  route_observer_mixin: ^1.5.0+1

dev_dependencies:
  flutter_test:
    sdk: flutter

flutter:
  uses-material-design: true

  assets:
    - assets/images/
    - assets/audio/

  fonts:
    - family: Luminari
      fonts:
        - asset: assets/fonts/Luminari/Luminari-Regular.ttf
          style: normal
          weight: 500
        - asset: assets/fonts/Luminari/Luminari-Regular.woff
          style: normal
          weight: 500
    - family: SourceSansPro
      fonts:
        - asset: assets/fonts/Source_Sans_Pro/SourceSansPro-Regular.ttf
          style: normal
          weight: 500
    - family: OpenSans
      fonts:
        - asset: assets/fonts/OpenSans/OpenSans-Regular.ttf
          style: normal
          weight: 500
        - asset: assets/fonts/OpenSans/OpenSans-Bold.ttf
          weight: 700
    - family: Quicksand
      fonts:
        - asset: assets/fonts/Quicksand/Quicksand-Regular.ttf
          style: normal
          weight: 500
        - asset: assets/fonts/Quicksand/Quicksand-Medium.ttf
        - asset: assets/fonts/Quicksand/Quicksand-Light.ttf
        - asset: assets/fonts/Quicksand/Quicksand-Bold.ttf
          weight: 700
    - family: Raleway
      fonts:
        - asset: assets/fonts/Raleway/Raleway-Regular.ttf
          style: normal
          weight: 500
        - asset: assets/fonts/Raleway/Raleway-Bold.ttf
          weight: 700
        - asset: assets/fonts/Raleway/Raleway-Black.ttf
          weight: 900
    - family: RobotoCondensed
      fonts:
        - asset: assets/fonts/RobotoCondensed/RobotoCondensed-Regular.ttf
          style: normal
          weight: 500
        - asset: assets/fonts/RobotoCondensed/RobotoCondensed-Bold.ttf
          weight: 700
        - asset: assets/fonts/RobotoCondensed/RobotoCondensed-Light.ttf
          weight: 300
        - asset: assets/fonts/RobotoCondensed/RobotoCondensed-Italic.ttf
          style: italic
    - family: AppIcons
      fonts:
        - asset: assets/fonts/AppIcons/AppIcons.ttf
2
  • Thanks for asking this question, sometimes a good question can save people's time more that an answer.
    – AmerllicA
    Jan 25, 2023 at 15:49
  • I just added two other flags because this issue happens for RN too, and it is specifically related to Android build.
    – AmerllicA
    Jan 25, 2023 at 16:07

9 Answers 9

94

Updating to a newer kotlin version in build.gradle seems to solve the issue for me.

ext.kotlin_version = '1.4.32'

Solution from a related question

4
  • 3
    Thanks bakavic. I updated my Kotlin version from '1.3.50' to '1.5.10' (at android/build.gradle:2) and now is working again. Thank you so much! Jun 5, 2021 at 3:42
  • This worked for me too. Thanks! How come the OP didn't accept this as the accepted answer?
    – Osh Mansor
    Jul 4, 2021 at 11:35
  • Is it safe to update kotlin version, will lower api versions stop working and why does the error log in the question not mention what the current ext.kotlin_version?
    – lolelo
    Aug 3, 2021 at 9:41
  • 1
    It says there All binaries are backwards compatible, i.e. a newer compiler can read older binaries here: kotlinlang.org/docs/…
    – lolelo
    Aug 3, 2021 at 9:48
14

this happened to me after i added the workmanager plugin. to fix this, go to the android folder and in build.gradle use kotlin version 1.5.31

ext.kotlin_version = '1.5.31'
11

Please open android > build.gradle

Inside buildscript { }, you'll find ext.kotlin_version (Line 2 in file)

Replace whatever version it is with Latest Stable Kotlin Version

As of July 28, 2021 it is, ext.kotlin_version = '1.5.21'

Now, re-install the app. If it's already running, press Stop then press Run (Play) again.

5

Go to android>build.gradle and update your Kotlin version.

ext.kotlin_version = '1.4.32'  

This worked for me.

3

As for Flutter 2.10 there was a breaking change with required Kotlin version - Ref.

Here is a migration guide

This means that if you previosly created a project a long time ago (with java) then it means you need to add Kotlin plugin to build.gradle. I suggest launching flutter create --org com.sample sample which generates up-to-date configuration. Then you can check what is missing.

2

Plese check the current kotlin (installed) version by ANdroidstudio->Preferences->Languages& frameworks->kotlinenter image description here

In this 1.6.10 is the version . Now Open Android build.gradle

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

Change it ..

enter image description here

ext.kotlin_version** = '1.6.10'

0

this happened to me after i added the Room plugin. to fix this, go to the android folder and in build.gradle use kotlin version 1.5.31

I changed from

ext { kotlin_version = "1.3.72" nav_version = "2.3.1"
room_version = '2.3.0' }

replace with

ext { kotlin_version = "1.5.31" nav_version = "2.3.1" room_version = '2.3.0' }

0

To be fair, my project is running on React Native and I was using react-native-track-player, everything was good on iOS but on Android build I got this error, so my solution was updating the Kotlin version to the compatible version with the others, in the android/build.gradle file I changed the versions to these

buildscript {
    ext {
        buildToolsVersion = "33.0.0"
        minSdkVersion = 24
        compileSdkVersion = 33
        targetSdkVersion = 33
        supportLibVersion = "28.0.0"
        androidXAnnotation = "1.1.0"
        androidXBrowser = "1.0.0"
        kotlinVersion = "1.6.10"
        kotlin_version = "1.6.10"

        if (System.properties['os.arch'] == "aarch64") {
            // For M1 Users we need to use the NDK 24 which added support for aarch64
            ndkVersion = "25.0.8775105"
        } else {
            // Otherwise we default to the side-by-side NDK version from AGP.
            ndkVersion = "21.4.7075529"
        }

    }
    repositories {
        google()
        mavenCentral()
    }

Just one more thing, I was using kotlinVersion to pass the version of Kotlin but it seems RNTP or something else uses kotlin_version.

0

I got a similar error when adding flutter_widget_from_html to my flutter app.

In newer versions of flutter, it seems the kotlin version is set inside android/settings.gradle:

plugins {
    id "org.jetbrains.kotlin.android" version "1.7.10" apply false
}

One of the error messages I got was this:
The binary version of its metadata is 1.9.0, expected version is 1.7.1.

So you can see the expected version (1.7.1) matches the version in the android/settings.gradle file.

Changing it to 1.9.0 solved my app no longer building.

plugins {
    id "org.jetbrains.kotlin.android" version "1.9.0" apply false
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.