I am working on a Flutter project and I’m facing an issue related to Kotlin versions. When I try to build my project, I get the following error messages indicating a version mismatch between Kotlin modules:
e: C:/Users/digit/.gradle/caches/transforms-3/431ce31617111116ed092b20fb775fda/transformed/jetified-kotlin-stdlib-1.9.0.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.7.1.
e: C:/Users/digit/.gradle/caches/transforms-3/431ce31617111116ed092b20fb775fda/transformed/jetified-kotlin-stdlib-1.9.0.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.7.1.
e: C:/Users/digit/.gradle/caches/transforms-3/431ce31617111116ed092b20fb775fda/transformed/jetified-kotlin-stdlib-1.9.0.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.7.1.
e: C:/Users/digit/.gradle/caches/transforms-3/6327b6d5cbee3dd5c434505ea5de9c0a/transformed/jetified-firebase-analytics-ktx-22.0.1-api.jar!/META-INF/java.com.google.android.libraries.firebase.firebase_analytics_ktx_granule.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.7.1.
e: C:/Users/digit/.gradle/caches/transforms-3/648640f83817e7438e3934ba83addfe2/transformed/jetified-play-services-measurement-api-22.0.1-api.jar!/META-INF/java.com.google.android.gmscore.integ.client.measurement_api_measurement_api.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.7.1.
e: C:/Users/digit/.gradle/caches/transforms-3/c321e7444a5c731da2398570d6ef04f1/transformed/jetified-kotlin-stdlib-common-1.9.0.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.9.0, expected version is 1.7.1.
t
Additionally, I receive this message indicating the need for a newer version of the Kotlin Gradle plugin:
[!] 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 C:UsersdigitDocumentsflutter projectsandroidbuild.gradle:
ext.kotlin_version = '<latest-version>'
My Current Setup
Here are the relevant parts of my android/build.gradle and android/app/build.gradle files:
android/build.gradle:
buildscript {
ext.kotlin_version = '1.9.0' // Updated to the latest version
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.4.2' // Updated Gradle Plugin
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.4.2'
classpath 'com.google.dagger:hilt-android-gradle-plugin:2.44'
}
}
allprojects {
repositories {
google()
mavenCentral()
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
}
tasks.register("clean", Delete) {
delete rootProject.buildDir
}
android/app/build.gradle:
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-kapt'
id 'com.google.gms.google-services'
id 'com.google.dagger.hilt.android'
id 'dev.flutter.flutter-gradle-plugin'
}
def localProperties = new Properties()
def localPropertiesFile = rootProject.file("local.properties")
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader("UTF-8") { reader ->
localProperties.load(reader)
}
}
def flutterVersionCode = localProperties.getProperty("flutter.versionCode")
if (flutterVersionCode == null) {
flutterVersionCode = "1"
}
def flutterVersionName = localProperties.getProperty("flutter.versionName")
if (flutterVersionName == null) {
flutterVersionName = "1.0"
}
android {
namespace = "com.muhasebepro.muhasebe_pro_finall"
compileSdkVersion 34
ndkVersion = flutter.ndkVersion
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
defaultConfig {
applicationId "com.muhasebepro.muhasebe_pro_finall"
minSdkVersion 24
targetSdkVersion 34
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
buildTypes {
release {
signingConfig signingConfigs.debug
}
}
}
flutter {
source = '../..'
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation platform('com.google.firebase:firebase-bom:31.2.3')
implementation 'com.google.firebase:firebase-analytics-ktx'
implementation 'com.google.dagger:hilt-android:2.44'
kapt 'com.google.dagger:hilt-compiler:2.44'
}
apply plugin: 'kotlin-kapt'
Steps I Have Tried
Updated Kotlin version to 1.9.0 in android/build.gradle.
Ensured that all dependencies use the same Kotlin version.
Cleaned and rebuilt the project using flutter clean and flutter pub get.
Request
How can I resolve this version mismatch issue and ensure that all modules use the same compatible version of Kotlin?
What I Tried and Expected
I am working on a Flutter project and encountered issues related to Kotlin versions during the build process. Here’s what I have tried so far:
Updated Kotlin Version: I updated the Kotlin version to 1.9.0 in my android/build.gradle file as suggested by the error message.
Synchronized Dependencies: I ensured that all dependencies in my build.gradle files are using the same version of Kotlin.
Cleaned and Rebuilt the Project: I used flutter clean and flutter pub get to clean and fetch the dependencies again, hoping to resolve any conflicts.
Checked for Duplicate Dependencies: I verified that there are no duplicate dependencies that might be causing the conflict.
2
Answers
You can try to force all packages to use the same kotlin version.
Just add the following to your app/build.gradle, just before apply plugin and just after dependencies.
any answer for this still trying to fix it