Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.8.0, expected version is 1.6.0 - kotlin

C:/Users/LENOVO/.gradle/caches/transforms-2/files-2.1/33fa47401fa8ac91195ccfa117fbdede/jetified-kotlin-stdlib-common-1.8.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.8.0, expected version is 1.6.0.

I had the same error, I've solved it as follow:
Add it in build.gradle (module)
kotlinOptions {
jvmTarget = '1.8'
}
composeOptions {
kotlinCompilerExtensionVersion '1.4.0'
}
Add it in build.gradle(project)
buildscript {
ext {
compose_version = '1.3.3'
}
}
plugins {
[...]
id 'org.jetbrains.kotlin.android' version '1.8.0' apply false
}

Related

The binary version of its metadata is 1.8.0, expected version is 1.6.0. Module was compiled with an incompatible version of Kotlin

C:/Users/LENOVO/.gradle/caches/transforms-2/files-2.1/2bcd0a6b95744b6f0ee26f9336bd22eb/jetified-annotation-jvm-1.6.0-beta01.jar!/META-INF/annotation.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.8.0, expected version is 1.6.0.
buildscript {
ext.kotlin_version = '1.4.32'
ext.anko_version='0.10.8'
repositories {
jcenter()
maven {
url 'https://maven.google.com/'
name 'Google'
}
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.2'
classpath 'com.google.gms:google-services:4.3.3'
classpath 'org.greenrobot:greendao-gradle-plugin:3.2.1'
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10'
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.4.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
// Add the dependency for the Performance Monitoring plugin
classpath 'com.google.firebase:perf-plugin:1.4.1'
}
}
This project contains a few incompatible or even dangerous things, that also lead you to the problem you're having:
jcenter() is not in service anymore, so it should be replaced by mavenCentral() or your dependencies will not be correctly resolved.
You specify both Kotlin 1.4.32 (no longer maintained) and 1.6.10 (no longer ideal, but still usable) and the classes will definitely not be compatible between them.
Some of your other dependencies might be even newer and use Kotlin 1.8.0, so your older runtimes won't be able to read their metadata.
Recently, I faced a similar issue on creating a new project in Android studio with Compose Material3 template.
So I upgraded below libraries/plugins solve my issue. I also attached my gradle files for reference.
kotlin version to 1.8.0
kotlinCompilerExtensionVersion '1.4.0'
compose_version to 1.3.1
build.gradle(app)
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
}
android {
namespace 'com.hometech.anatomymuscles'
compileSdk 33
defaultConfig {
applicationId "com.hometech.anatomymuscles"
minSdk 23
targetSdk 33
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary true
}
}
buildTypes {
release {
minifyEnabled 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
}
composeOptions {
kotlinCompilerExtensionVersion '1.4.0'
}
packagingOptions {
resources {
excludes += '/META-INF/{AL2.0,LGPL2.1}'
}
}
}
dependencies {
implementation 'androidx.core:core-ktx:1.9.0'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.5.1'
implementation 'androidx.activity:activity-compose:1.6.1'
implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
implementation 'androidx.compose.material3:material3:1.1.0-alpha05'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"
debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_version"
}
build.gradle(project)
buildscript {
ext {
compose_version = '1.3.3'
}
}// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '7.4.1' apply false
id 'com.android.library' version '7.4.1' apply false
id 'org.jetbrains.kotlin.android' version '1.8.0' apply false
}

Unresolved reference for gradle dependency

All the classes of the library are shown in the libs folder but when I try to use any reference to it, it just says it is an unresolved reference.
Unresolved reference error
build.gradle.kts:
plugins {
kotlin("jvm") version "1.8.0"
kotlin("plugin.serialization") version "1.8.0"
id("com.github.johnrengelman.shadow") version "7.1.2"
id("io.papermc.paperweight.userdev") version "1.3.6"
}
group = "me.supehsloht"
version = "1.0-SNAPSHOT"
repositories {
mavenCentral()
maven("https://repo.rapture.pw/repository/maven-snapshots/")
}
dependencies {
compileOnly("org.jetbrains.kotlin:kotlin-stdlib:1.8.0")
compileOnly("org.jetbrains.kotlinx:kotlinx-serialization-json:1.4.1")
compileOnly("com.charleskorn.kaml:kaml:0.49.0")
paperDevBundle("1.19.3-R0.1-SNAPSHOT")
compileOnly(files("libs/Core.jar"))
compileOnly(files("libs/AdvancedSlimeWorldManagerAPI.jar"))
}
java {
toolchain.languageVersion.set(JavaLanguageVersion.of(17))
}
tasks {
compileJava {
options.encoding = Charsets.UTF_8.name()
options.release.set(17)
}
compileKotlin {
kotlinOptions.jvmTarget = "17"
}
reobfJar {
outputJar.set(layout.buildDirectory.file("libs/${project.name.capitalize()}.jar"))
}
}
I already had this problem, then it was fixed by not shading the kotlin stdlib into the jar but that didn't work this time.

Kotlin NoSuchMethodError after installing a library that enables a plugin

I want to experience a library called arrow analysis
My build.gradle.kts file looks as follows:
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
kotlin("jvm") version "1.7.10"
}
group = "org.example"
version = "1.0-SNAPSHOT"
repositories {
mavenCentral()
}
dependencies {
testImplementation(kotlin("test"))
implementation("io.arrow-kt:arrow-core:1.1.2")
}
buildscript {
dependencies {
classpath("io.arrow-kt.analysis.kotlin:io.arrow-kt.analysis.kotlin.gradle.plugin:2.0")
}
}
apply(plugin = "io.arrow-kt.analysis.kotlin")
tasks.test {
useJUnitPlatform()
}
tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "1.8"
}
after an attempt to build the project, I get the following error:
java.lang.NoSuchMethodError: 'org.jetbrains.kotlin.psi.KtExpression org.jetbrains.kotlin.resolve.calls.callUtil.CallUtilKt.getReceiverExpression(org.jetbrains.kotlin.resolve.calls.model.ResolvedCall)'
at arrow.meta.plugins.analysis.phases.analysis.solver.ast.kotlin.KotlinResolvedCall.getReceiverExpression(KotlinResolvedCall.kt:37)
at arrow.meta.plugins.analysis.phases.analysis.solver.ResolvedCallUtilsKt.allArgumentExpressions(ResolvedCallUtils.kt:75)
at arrow.meta.plugins.analysis.phases.analysis.solver.ResolvedCallUtilsKt.arg(ResolvedCallUtils.kt:119)
at arrow.meta.plugins.analysis.phases.analysis.solver.check.ExpressionsKt.controlFlowAnyFunction(Expressions.kt:438)
at arrow.meta.plugins.analysis.phases.analysis.solver.check.ExpressionsKt.checkCallExpression(Expressions.kt:397)
at arrow.meta.plugins.analysis.phases.analysis.solver.check.ExpressionsKt.fallThrough(Expressions.kt:260)
at arrow.meta.plugins.analysis.phases.analysis.solver.check.ExpressionsKt.access$fallThrough(Expressions.kt:1)
at arrow.meta.plugins.analysis.phases.analysis.solver.check.ExpressionsKt$checkExpressionConstraints$2.invoke(Expressions.kt:244)
at arrow.meta.plugins.analysis.phases.analysis.solver.check.ExpressionsKt$checkExpressionConstraints$2.invoke(Expressions.kt:157)
at arrow.meta.continuations.ContSeq$flatMap$1.invokeSuspend(ContSeq.kt:60)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
I checked the source code, and everything seems to be in place. Did I something wrong as per the instructions to install this library which is denoted as follows:
buildscript {
dependencies {
classpath("io.arrow-kt.analysis.kotlin:io.arrow-kt.analysis.kotlin.gradle.plugin:2.0")
}
}
apply(plugin = "io.arrow-kt.analysis.kotlin")
You need to apply the plugin inside the plugins block and in the same fashion you're applying the Kotlin JVM plugin.
They mention to use it like this on their official docs
plugins {
kotlin("multiplatform") version "1.6.21"
// other plugins
id("io.arrow-kt.analysis.kotlin") version "2.0.2"
}
buildscript {
repositories {
mavenCentral()
}
}

How Do I Resolve This Type Mismatch?

So I was working on converting my build.gradle (Which uses Groovy) to a build.gradle.kts (Which uses Kotlin) and this is what I got so far:
Groovy Original:
plugins {
id 'java'
id 'org.jetbrains.kotlin.jvm' version '1.3.72'
id 'com.github.johnrengelman.shadow' version '5.2.0'
}
group 'com.smushytaco'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
maven {
url 'https://papermc.io/repo/repository/maven-public/'
}
}
dependencies {
implementation group: 'org.jetbrains.kotlin', name: 'kotlin-stdlib', version: '1.3.72'
//https://papermc.io/javadocs/paper/1.16/overview-summary.html
compileOnly group: 'com.destroystokyo.paper', name: 'paper-api', version: '1.16.1-R0.1-SNAPSHOT'
}
shadowJar {
getArchiveClassifier().set('')
project.configurations.implementation.canBeResolved = true
configurations = [project.configurations.implementation]
relocate 'kotlin', 'com.smushytaco.src.main.kotlin.com.smushytaco.plugin'
}
build.dependsOn shadowJar
Kotlin Conversion:
plugins {
java
kotlin("jvm") version("1.3.72")
id("com.github.johnrengelman.shadow") version("5.2.0")
}
group = "com.smushytaco"
version = "1.0-SNAPSHOT"
repositories {
mavenCentral()
maven("https://papermc.io/repo/repository/maven-public/")
}
dependencies {
implementation("org.jetbrains.kotlin", "kotlin-stdlib", "1.3.72")
//https://papermc.io/javadocs/paper/1.16/overview-summary.html
compileOnly("com.destroystokyo.paper", "paper-api", "1.16.1-R0.1-SNAPSHOT")
}
tasks {
shadowJar {
archiveClassifier.set("")
project.configurations.implementation.get().isCanBeResolved = true
// Type Mismatch:
// Required: (Mutable)List<Configuration!>!
//Found: Array<NamedDomainObjectProvider<Configuration>>
configurations = [project.configurations.implementation]
relocate("kotlin", "com.smushytaco.src.main.kotlin.com.smushytaco.plugin")
}
build {
dependsOn(shadowJar)
}
}
I commented the error I'm getting with the Kotlin rewrite, why does it work with the original Groovy one and not with this one? How do I fix this error?
Use this:
configurations = listOf(project.configurations.implementation.get())

What are the requirements for gradle.kts generated by spring initializr?

I modified the build.gradle file of the newly created gradle project named build.gradle.kts, and then copied the build.gradle.kts content of the demo project generated by spring initializr, and then build, this file reported a lot of errors, but spring initializr project can be built correctly.
The two build.gradle.kts are exactly the same. What's wrong?
This is the wrong screenshot https://s2.ax1x.com/2019/08/21/mNvASA.png
This is the correct screenshot https://s2.ax1x.com/2019/08/21/mNvEQI.png
This is the content
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
id("org.springframework.boot") version "2.1.7.RELEASE"
id("io.spring.dependency-management") version "1.0.8.RELEASE"
kotlin("jvm") version "1.2.71"
kotlin("plugin.spring") version "1.2.71"
}
group = "com.example"
version = "0.0.1-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_1_8
repositories {
mavenCentral()
}
dependencies {
api("org.springframework.boot:spring-boot-starter")
api("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
testImplementation("org.springframework.boot:spring-boot-starter-test")
}
tasks.withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs = listOf("-Xjsr305=strict")
jvmTarget = "1.8"
}
}