1

I’m working on a Flutter app and trying to run it on Android using:

  • Kotlin version: 2.2.0
  • Gradle version: 8.14.3
  • JVM target: 17

But I keep getting this error during the build:

e: .../jetified-play-services-measurement-api-23.0.0-api.jar!/META-INF/...kotlin_moduleModule was compiled with an incompatible version of Kotlin. The binary version of its metadata is 2.1.0, expected version is 1.8.0.
...
FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app: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 9s

┌─ 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      │
│ /../android │
│ /settings.gradle.                                                                                │
│                                                                                                  │
│ Alternatively (if your project was created before Flutter 3.19), update                          │
│ /../android │
│ /build.gradle                                                                                    │
│ ext.kotlin_version = '<latest-version>'                                                          │
└──────────────────────────────────────────────────────────────────────────────────────────────────┘
Error: Gradle task assembleDebug failed with exit code 1

I tried:

  • Upgrading the Kotlin Gradle plugin to 2.2.0
  • Setting jvmTarget to 17
  • Cleaning with flutter clean and running again

None of these worked.

To fix the issue, I have end up trying to exclude the problematic modules like this:

implementation('com.google.firebase:firebase-analytics:23.0.0') {
    exclude group: 'com.google.android.gms', module: 'play-services-measurement-api'
    exclude group: 'com.google.android.gms', module: 'play-services-measurement-impl'
}

These exclusions don’t affect basic Firebase Analytics functionality and allow your build to complete successfully in debug mode.

However attempting to run flutter build apk --release will lead you to another error:

Execution failed for task ':app:minifyReleaseWithR8'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.R8Task$R8Runnable

1 Answer 1

3

Eventually, I discovered that the issue was coming from a transitive dependency of Firebase Analytics. The error message doesn’t mention Firebase directly, which made debugging very difficult.

To help others:

Check your android/app/build.gradle or android/build.gradle file and see if you’re using this:

implementation 'com.google.firebase:firebase-analytics:23.0.0'

If yes, then that’s likely the problem.

Root Cause

firebase-analytics:23.0.0 bundles transitive dependencies like:
• play-services-measurement-api
• play-services-measurement-impl

These internal libraries are compiled with Kotlin 2.1.0 metadata, which is not compatible with older Kotlin compilers. Even if you’re on a newer Kotlin version like 2.2.0, this version mismatch can still break your release build, especially when using R8 or Proguard with shrinking enabled.

Fix

Downgrade Firebase Analytics to the last known version that does not use Kotlin 2.1 metadata:

implementation 'com.google.firebase:firebase-analytics:21.5.0'

This resolved the issue for me.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.