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