I use Android Studio 2024.1.2, java 1.8, kotlin 1.9.0, as written in the Studio settings windows.
There is a kotlin project that has been successfully compiled until today, when I decided to add FCM notifications. I have added a MyFirebaseMessagingService class that initially was generated as java class, and not .kt class.
After that I can't build the project due to error:
Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The actual metadata version is 2.1.0, but the compiler version 1.9.0 can read versions up to 2.0.0.
The class is loaded from C:/Users/Administrator/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/2.1.20/aa8ca79cd50578314f6d1180c47cbe14c0fee567/kotlin-stdlib-2.1.20.jar!/kotlin/Unit.class
although I even do not use 2.1.0 version: in the Settings-Other settings - Kotlin compiler it is 1.9.0.
Switching to 2.1.0 in settings does not avoid error.
I changed java class to kotlin class, and now there are no java files in project - does not change anything.
Deleting whole
C:/Users/Administrator/.gradle/cachesfolder does not avoid error - filekotlin-stdlib-2.1.20.jargenerates every time I try to build."Clean project", "Invalidate caches", "Rebuild project" - does not avoid the error.
build.gradle.kts (:app) :
import org.gradle.internal.impldep.bsh.commands.dir
import org.gradle.internal.impldep.org.junit.experimental.categories.Categories.CategoryFilter.include
plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.kotlin.android)
id("com.google.gms.google-services")
}
android {
namespace = "com.text.text"
compileSdk = 36
defaultConfig {
applicationId = "com.text.text"
minSdk = 23
targetSdk = 36
versionCode = 52
versionName = "3.92"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary = true
}
}
buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
buildFeatures {
compose = true
dataBinding = true
viewBinding = true
}
composeOptions {
kotlinCompilerExtensionVersion = "1.5.1"
}
packaging {
resources {
excludes += "/META-INF/{AL2.0,LGPL2.1}"
}
}
}
dependencies {
implementation(libs.androidx.core.ktx)
implementation(libs.androidx.lifecycle.runtime.ktx)
implementation(libs.androidx.activity.compose)
implementation(platform(libs.androidx.compose.bom))
implementation(libs.androidx.ui)
implementation(libs.androidx.ui.graphics)
implementation(libs.androidx.ui.tooling.preview)
implementation(libs.androidx.material3)
implementation(libs.androidx.appcompat)
implementation(libs.androidx.webkit)
implementation(libs.firebase.messaging)
implementation(libs.androidx.work.runtime)
testImplementation(libs.junit)
androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.androidx.espresso.core)
androidTestImplementation(platform(libs.androidx.compose.bom))
androidTestImplementation(libs.androidx.ui.test.junit4)
debugImplementation(libs.androidx.ui.tooling)
debugImplementation(libs.androidx.ui.test.manifest)
val navigationVersion = "2.1.0"
val fragmentVersion = "1.2.0-rc03"
implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))
implementation("androidx.legacy:legacy-support-v4:1.0.0")
implementation("com.google.android.material:material:1.5.0")
implementation("androidx.constraintlayout:constraintlayout:1.1.3")
implementation("androidx.navigation:navigation-fragment:$navigationVersion")
implementation("androidx.fragment:fragment:$fragmentVersion")
implementation("androidx.fragment:fragment-ktx:$fragmentVersion")
implementation("androidx.media:media:1.6.0")
implementation("androidx.credentials:credentials:1.1.1")
implementation("androidx.credentials:credentials-play-services-auth:1.1.1")
implementation("com.google.android.libraries.identity.googleid:googleid:1.1.1")
implementation("com.google.android.gms:play-services-auth:21.2.0")
implementation("com.android.installreferrer:installreferrer:2.2")
implementation("com.google.firebase:firebase-core:21.1.1")
implementation("com.google.firebase:firebase-analytics-ktx:21.4.0")
implementation("com.facebook.android:facebook-android-sdk:[8,9)")
implementation(platform("com.google.firebase:firebase-bom:32.0.0"))
implementation ("com.google.firebase:firebase-messaging")
}
I've added two last implementations manually (or at least the last one), and perhaps some were added automatically. Removing two last does not avoid the error.
Another build.gradle.kts
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
alias(libs.plugins.android.application) apply false
alias(libs.plugins.kotlin.android) version "1.9.0" apply false
id("com.google.gms.google-services") version "4.4.4" apply false
}