«Класс «kotlin.Unit» был скомпилирован с несовместимой версией» после добавления класса JavaAndroid

Форум для тех, кто программирует под Android
Ответить
Anonymous
 «Класс «kotlin.Unit» был скомпилирован с несовместимой версией» после добавления класса Java

Сообщение Anonymous »

Я использую Android Studio 2024.1.2, java 1.8, kotlin 1.9.0, как написано в окнах настроек Studio.
Есть проект kotlin, который успешно компилировался до сегодняшнего дня, когда я решил добавить уведомления FCM. Я добавил класс MyFirebaseMessagingService, который изначально был создан как класс Java, а не класс .kt.
После этого я не могу собрать проект из-за ошибки:
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

хотя я даже версией 2.1.0 не пользуюсь: в Настройках-Other settings - Компилятор Kotlin это 1.9.0.
  • Переход на 2.1.0 в настройках не позволяет избежать ошибки.
  • Я поменял класс Java на класс Kotlin, и теперь в проекте нет Java-файлов - ничего не меняется.
  • Удаление всей папки C:/Users/Administrator/.gradle/caches не позволяет избежать ошибки - файл kotlin-stdlib-2.1.20.jar генерируется каждый раз, когда я пытаюсь собрать.
  • "Очистить проект", "Недействить кеши", "Перестроить проект" - не позволяет избежать ошибки.
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")
}


Я добавил две последние реализации вручную (или, по крайней мере, последнюю), и, возможно, некоторые из них были добавлены автоматически. Удаление двух последних не позволяет избежать ошибки.
Еще один 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

}

libs.version.toml файл:
[versions]
agp = "8.9.1"
kotlin = "1.9.0"
coreKtx = "1.13.1"
junit = "4.13.2"
junitVersion = "1.2.1"
espressoCore = "3.6.1"
lifecycleRuntimeKtx = "2.8.6"
activityCompose = "1.9.2"
composeBom = "2024.04.01"
appcompat = "1.7.0"
webkit = "1.12.1"
firebaseMessaging = "25.0.1"
workRuntime = "2.11.1"
core = "1.17.0"
activityKtx = "1.12.3"
appcompatVersion = "1.7.1"
credentials = "1.5.0"
installreferrer = "2.2"
playServicesAuth = "21.5.0"
googleid = "1.2.0"
playServicesMeasurementApi = "23.0.0"
workRuntimeKtx = "2.11.1"
firebaseMessagingKtx = "25.0.1"

[libraries]
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
junit = { group = "junit", name = "junit", version.ref = "junit" }
androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitVersion" }
androidx-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espressoCore" }
androidx-lifecycle-runtime-ktx = { group = "androidx.lifecycle", name = "lifecycle-runtime-ktx", version.ref = "lifecycleRuntimeKtx" }
androidx-activity-compose = { group = "androidx.activity", name = "activity-compose", version.ref = "activityCompose" }
androidx-compose-bom = { group = "androidx.compose", name = "compose-bom", version.ref = "composeBom" }
androidx-ui = { group = "androidx.compose.ui", name = "ui" }
androidx-ui-graphics = { group = "androidx.compose.ui", name = "ui-graphics" }
androidx-ui-tooling = { group = "androidx.compose.ui", name = "ui-tooling" }
androidx-ui-tooling-preview = { group = "androidx.compose.ui", name = "ui-tooling-preview" }
androidx-ui-test-manifest = { group = "androidx.compose.ui", name = "ui-test-manifest" }
androidx-ui-test-junit4 = { group = "androidx.compose.ui", name = "ui-test-junit4" }
androidx-material3 = { group = "androidx.compose.material3", name = "material3" }
androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" }
androidx-webkit = { group = "androidx.webkit", name = "webkit", version.ref = "webkit" }
firebase-messaging = { group = "com.google.firebase", name = "firebase-messaging", version.ref = "firebaseMessaging" }
androidx-work-runtime = { group = "androidx.work", name = "work-runtime", version.ref = "workRuntime" }
androidx-core = { group = "androidx.core", name = "core", version.ref = "core" }
androidx-activity-ktx = { group = "androidx.activity", name = "activity-ktx", version.ref = "activityKtx" }
appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompatVersion" }
androidx-credentials = { group = "androidx.credentials", name = "credentials", version.ref = "credentials" }
installreferrer = { group = "com.android.installreferrer", name = "installreferrer", version.ref = "installreferrer" }
play-services-auth = { group = "com.google.android.gms", name = "play-services-auth", version.ref = "playServicesAuth" }
googleid = { group = "com.google.android.libraries.identity.googleid", name = "googleid", version.ref = "googleid" }
play-services-measurement-api = { group = "com.google.android.gms", name = "play-services-measurement-api", version.ref = "playServicesMeasurementApi" }
androidx-work-runtime-ktx = { group = "androidx.work", name = "work-runtime-ktx", version.ref = "workRuntimeKtx" }
firebase-messaging-ktx = { group = "com.google.firebase", name = "firebase-messaging-ktx", version.ref = "firebaseMessagingKtx" }

[plugins]
android-application = { id = "com.android.application", version.ref = "agp" }
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }



Подробнее здесь: https://stackoverflow.com/questions/798 ... adding-a-j
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Android»