kotlin unit was compile with an incompatible version of kotlin - kotlin

Please i need help on how to resolve this error, I have searched all the answers in stack overflow but non of it solve the problem for me. I updated my kotlin when recently and when i wanted to run a new kotlin application, i got this error. I tried all the steps in stack overflow but non of it work.
Here is the error message
failed
:app:compileDebugKotlin
Runtime JAR files in the classpath should have the same version. These files were found in the classpath:
C:/Users/HP/newfolder/caches/transforms-3/a8b763bee6c7278a49a4c205da65b911/transformed/jetified-kotlin-stdlib-jdk8-1.5.30.jar (version 1.5)
C:/Users/HP/newfolder/caches/transforms-3/e478bf55927823f4da54fcc6c8971874/transformed/jetified-kotlin-stdlib-jdk7-1.5.30.jar (version 1.5)
C:/Users/HP/newfolder/caches/transforms-3/84c66d4f4ecf6f746e3716128956475c/transformed/jetified-kotlin-stdlib-1.6.0.jar (version 1.6)
C:/Users/HP/newfolder/caches/transforms-3/a891d209549d183ec22b0fd6f8a659f5/transformed/jetified-kotlin-stdlib-common-1.6.0.jar (version 1.6)
C:/Users/HP/newfolder/caches/transforms-3/18ec897b17c934613389ac8a536f0724/transformed/navigation-common-2.4.1-api.jar!/META-INF/navigation-common_release.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.4.2.
C:/Users/HP/newfolder/caches/transforms-3/345269ef286a72cb64a64bd63517dfe5/transformed/navigation-fragment-2.4.1-api.jar!/META-INF/navigation-fragment_release.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.4.2.
C:/Users/HP/newfolder/caches/transforms-3/5b512e38ccc4fbafd5962c1a47398a65/transformed/navigation-ui-2.4.1-api.jar!/META-INF/navigation-ui_release.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.4.2.
C:/Users/HP/newfolder/caches/transforms-3/84c66d4f4ecf6f746e3716128956475c/transformed/jetified-kotlin-stdlib-1.6.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.6.0, expected version is 1.4.2.
C:/Users/HP/newfolder/caches/transforms-3/9bfb36f4d787787665db8c5d2d65e8be/transformed/navigation-runtime-2.4.1-api.jar!/META-INF/navigation-runtime_release.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.4.2.
C:/Users/HP/newfolder/caches/transforms-3/a891d209549d183ec22b0fd6f8a659f5/transformed/jetified-kotlin-stdlib-common-1.6.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.6.0, expected version is 1.4.2.
C:/Users/HP/newfolder/caches/transforms-3/ae232c4ce48fac963ba307d71d188737/transformed/slidingpanelayout-1.2.0-api.jar!/META-INF/slidingpanelayout_release.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.4.2.
app/src/main/java/com/elijah/ukeme/messengerapp/MainActivity.kt
Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.4.2.
The class is loaded from C:/Users/HP/newfolder/caches/transforms-3/84c66d4f4ecf6f746e3716128956475c/transformed/jetified-kotlin-stdlib-1.6.0.jar!/kotlin/Unit.class
Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.4.2.
The class is loaded from C:/Users/HP/newfolder/caches/transforms-3/84c66d4f4ecf6f746e3716128956475c/transformed/jetified-kotlin-stdlib-1.6.0.jar!/kotlin/Unit.class
Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.4.2.
The class is loaded from C:/Users/HP/newfolder/caches/transforms-3/84c66d4f4ecf6f746e3716128956475c/transformed/jetified-kotlin-stdlib-1.6.0.jar!/kotlin/Unit.class
Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.4.2.
The class is loaded from C:/Users/HP/newfolder/caches/transforms-3/84c66d4f4ecf6f746e3716128956475c/transformed/jetified-kotlin-stdlib-1.6.0.jar!/kotlin/Unit.class
Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.4.2.
The class is loaded from C:/Users/HP/newfolder/caches/transforms-3/84c66d4f4ecf6f746e3716128956475c/transformed/jetified-kotlin-stdlib-1.6.0.jar!/kotlin/Unit.class
Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.4.2.
The class is loaded from C:/Users/HP/newfolder/caches/transforms-3/84c66d4f4ecf6f746e3716128956475c/transformed/jetified-kotlin-stdlib-1.6.0.jar!/kotlin/Unit.class
Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.4.2.
The class is loaded from C:/Users/HP/newfolder/caches/transforms-3/84c66d4f4ecf6f746e3716128956475c/transformed/jetified-kotlin-stdlib-1.6.0.jar!/kotlin/Unit.class
Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.4.2.
The class is loaded from C:/Users/HP/newfolder/caches/transforms-3/84c66d4f4ecf6f746e3716128956475c/transformed/jetified-kotlin-stdlib-1.6.0.jar!/kotlin/Unit.class
Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.4.2.
The class is loaded from C:/Users/HP/newfolder/caches/transforms-3/84c66d4f4ecf6f746e3716128956475c/transformed/jetified-kotlin-stdlib-1.6.0.jar!/kotlin/Unit.class
Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.4.2.
The class is loaded from C:/Users/HP/newfolder/caches/transforms-3/84c66d4f4ecf6f746e3716128956475c/transformed/jetified-kotlin-stdlib-1.6.0.jar!/kotlin/Unit.class
Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.4.2.
The class is loaded from C:/Users/HP/newfolder/caches/transforms-3/84c66d4f4ecf6f746e3716128956475c/transformed/jetified-kotlin-stdlib-1.6.0.jar!/kotlin/Unit.class
app/src/main/java/com/elijah/ukeme/messengerapp/fragments/ChatFragment.kt
Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.4.2.
The class is loaded from C:/Users/HP/newfolder/caches/transforms-3/84c66d4f4ecf6f746e3716128956475c/transformed/jetified-kotlin-stdlib-1.6.0.jar!/kotlin/Unit.class
app/src/main/java/com/elijah/ukeme/messengerapp/fragments/SearchFragment.kt
Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.4.2.
The class is loaded from C:/Users/HP/newfolder/caches/transforms-3/84c66d4f4ecf6f746e3716128956475c/transformed/jetified-kotlin-stdlib-1.6.0.jar!/kotlin/Unit.class
app/src/main/java/com/elijah/ukeme/messengerapp/fragments/SettingsFragment.kt
Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.4.2.
The class is loaded from C:/Users/HP/newfolder/caches/transforms-3/84c66d4f4ecf6f746e3716128956475c/transformed/jetified-kotlin-stdlib-1.6.0.jar!/kotlin/Unit.class
Here is my buil.gradle file
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'com.google.gms.google-services'
}
android {
compileSdkVersion 31
buildToolsVersion "30.0.2"
defaultConfig {
applicationId "com.elijah.ukeme.messengerapp"
minSdkVersion 19
targetSdkVersion 31
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
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'
}
}
dependencies {
//noinspection GradleDependency
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.5.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
implementation 'androidx.navigation:navigation-fragment-ktx:2.4.1'
implementation 'androidx.navigation:navigation-ui-ktx:2.4.1'
implementation 'com.google.firebase:firebase-auth:21.0.1'
implementation 'com.google.firebase:firebase-database:20.0.3'
implementation 'com.google.firebase:firebase-firestore:24.0.1'
implementation 'com.google.firebase:firebase-storage:20.0.0'
implementation 'com.google.firebase:firebase-messaging:23.0.0'
implementation 'de.hdodenhof:circleimageview:2.2.0'
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'com.rengwuxian.materialedittext:library:2.1.4'
implementation 'com.squareup.retrofit2:retrofit:2.3.0'
implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
And this is the build.gradle for app
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = "1.4.32"
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:4.1.3"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.3.10'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
This is the gradle-wrapper.properties
#Sat Mar 05 12:09:03 PST 2022
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.9-bin.zip

change the kotlin-gradle version to :
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.31"
If you face error: resource android:attr/lStar not found"
then change version of your android app to:
buildToolsVersion = "31.0.0" compileSdkVersion = 31 targetSdkVersion = 31
if you face issue More than one file was found with OS independent path 'lib/armeabi-v7a/libfbjni.so'
then add this inside app/build.gradle inside of android{...}
packagingOptions { pickFirst '**/*.so' }

down grade your kotlinx.core version to 1.6.0 , because 1.7.0 required java 11
implementation 'androidx.core:core-ktx:1.6.0'
and probably some of your dependencies also required java 11, like this one,
implementation 'com.google.android.material:material:1.5.0' down to 1.4.0
i advice you to downgrade some of your dependencies version, or update your android studio to the latest version

in file android/buid.gradlew
on top :
def REACT_NATIVE_VERSION = new File(['node', '--print',"JSON.parse(require('fs').readFileSync(require.resolve('react-native/package.json'), 'utf-8')).version"].execute(null, rootDir).text.trim())
in allprojects :
allprojects {
configurations.all {
resolutionStrategy {
force "com.facebook.react:react-native:" + REACT_NATIVE_VERSION
}
}
}

Related

The binary version of its metadata is 1.7.1, expected version is 1.5.1

C:/Users/khare/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-common/1.7.0/51736992f422993a1e741051bdf3c12801bc1ca1/kotlin-stdlib-common-1.7.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.7.1, expected version is 1.5.1.
What should I do ? How to fix it ?
in (dependencies) inside build.gradle(project)
convert from 1.5.x (x) in my case is (20)
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.20"
to 1.7.10
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.10"
enter image description here
Just go to build.gradle(Project:yourProjectName)
Change
plugins {
...
id 'org.jetbrains.kotlin.android' version '1.5.x' apply false
...
}
[1.5.x means x version number at your case such as 1.5.1]
To
plugins {
...
id 'org.jetbrains.kotlin.android' version '1.7.10' apply false
...
}
It works at my case..
This is because of the Kotlin version of your Gradle project.
Please upgrade your Kotlin library version.
For more detail, check the below link.
Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.5.1, expected version is 1.1.15
Change build.gradle (project)
buildscript {
ext.kotlin_version = '1.7.10'
repositories {
google()
mavenCentral()
maven {
url 'https://jitpack.io'
}
}
dependencies {
classpath 'com.google.gms:google-services:4.3.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
plugins {
id 'com.android.application' version '7.2.2' apply false
id 'com.android.library' version '7.2.2' apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}

"Unresolved reference: sourceCompatibility" after upgrading Gradle build to Kotlin 1.7.0

Following some answers at Cannot inline bytecode built with JVM target 1.8 into bytecode that is being built with JVM target 1.6 I have a Kotlin Gradle DSL script containing
tasks.compileKotlin {
sourceCompatibility = JavaVersion.VERSION_11.toString()
targetCompatibility = JavaVersion.VERSION_11.toString()
kotlinOptions {
jvmTarget = "11"
}
}
but after upgrading to Kotlin 1.7.0 I get the exception
Unresolved reference: sourceCompatibility
Unresolved reference: targetCompatibility
It is clear to me they have apparently removed these, as I found it listed at https://kotlinlang.org/docs/whatsnew17.html#changes-in-compile-tasks
My question is, what do I replace it with? How should I ensure to keep compatibility?
Setting the JVM target, and the Kotlin API and Language versions can be done by configuring all KotlinCompile tasks.
// build.gradle.kts
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
kotlin("jvm") version "1.7.0"
}
// configure all Kotlin compilation tasks,
// using the Gradle configuration avoidance API
tasks.withType<KotlinCompile>().configureEach {
kotlinOptions {
jvmTarget = "11"
apiVersion = "1.6"
languageVersion = "1.6"
}
// you can also add additional compiler args,
// like opting in to experimental features
kotlinOptions.freeCompilerArgs += listOf(
"-opt-in=kotlin.RequiresOptIn",
)
}
apiVersion restricts the use of declarations to those from the specified version of bundled libraries
languageVersion means the compiled code will be compatible with the specified version of Kotlin
All the compiler options are documented here. There is also additional documentation for other build tools, like Maven and Ant.
You can use the new Toolchains feature to set the version of Java that will be used to compile the project.
// build.gradle.kts
kotlin {
jvmToolchain {
languageVersion.set(JavaLanguageVersion.of("11"))
}
}
Read more: Gradle Java toolchains support

Why Kotlin 1.6.x uses kotlinx-coroutines 1.5.2 by default

I use Kotlin 1.6.20 in my Gradle project and It uses dependency kotlinx-coroutines 1.5.2 by default.
build.gradle.kts
plugins {
...
kotlin("jvm") version "1.6.20"
}
dependencies {
...
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm")
}
But latest version is 1.6.1.
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.6.1")
Stability reason?

Kotlin + Gradle for JVM New Module Error in IntelliJ

My project is composed of Kotlin/JVM + Gradle
I'm trying to add a module
After creating the module it gives me a single files:
|--main-project
|----new-module
|------build.gradle.kts
|--<other-main-project-files>
module gradle:
plugins {
kotlin("jvm") version "1.4.32"
}
group = "com.example"
version = "0.0.1"
repositories {
mavenCentral()
}
dependencies {
implementation(kotlin("stdlib"))
}
It gives me an error Unresolved reference implementation and I can't create kotlin/java files
I have no issue if I use java instead of kotlin/jvm
I fixed the problem after going through Gradle logs
kotlin("jvm") version "1.4.32"
should be changed to
kotlin("jvm")

How to resolve conflict in kotlin libraries when creating gradle plugin in kotlin

Trying to create a plugin using latest kotlin version 1.4.21 so it conflicts with 1.3.72 bundled in gradle, when I build it complains with log below, is there a way for me to exclude the kotlin libs bundled in gradle?:
w: Runtime JAR files in the classpath should have the same version. These files were found in the classpath:
C:/Users/xxx/.gradle/wrapper/dists/gradle-6.7-bin/efvqh8uyq79v2n7rcncuhu9sv/gradle-6.7/lib/kotlin-stdlib-1.3.72.jar (version 1.3)
C:/Users/xxx/.gradle/wrapper/dists/gradle-6.7-bin/efvqh8uyq79v2n7rcncuhu9sv/gradle-6.7/lib/kotlin-stdlib-common-1.3.72.jar (version 1.3)
C:/Users/xxx/.gradle/wrapper/dists/gradle-6.7-bin/efvqh8uyq79v2n7rcncuhu9sv/gradle-6.7/lib/kotlin-stdlib-jdk7-1.3.72.jar (version 1.3)
C:/Users/xxx/.gradle/wrapper/dists/gradle-6.7-bin/efvqh8uyq79v2n7rcncuhu9sv/gradle-6.7/lib/kotlin-stdlib-jdk8-1.3.72.jar (version 1.3)
C:/Users/xxx/.gradle/wrapper/dists/gradle-6.7-bin/efvqh8uyq79v2n7rcncuhu9sv/gradle-6.7/lib/kotlin-reflect-1.3.72.jar (version 1.3)
C:/Users/xxx/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jdk8/1.4.21-2/fc405f82531d86896a20e9aab54129dc59f86920/kotlin-stdlib-jdk8-1.4.21-2.jar (version 1.4)
C:/Users/xxx/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-reflect/1.4.21-2/27a286ba08e5db21b04792befbb584d656e439e7/kotlin-reflect-1.4.21-2.jar (version 1.4)
C:/Users/xxx/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jdk7/1.4.21-2/813d63537c9df0ee0184f2fada6bc040b1328395/kotlin-stdlib-jdk7-1.4.21-2.jar (version 1.4)
C:/Users/xxx/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.4.21-2/e9840ab2db3095cf168d5425899be9fc97f848ca/kotlin-stdlib-1.4.21-2.jar (version 1.4)
C:/Users/xxx/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-common/1.4.21-2/3c1c0910bfba8bdb1a14303002d162b96a3aad11/kotlin-stdlib-common-1.4.21-2.jar (version 1.4)
w: Consider providing an explicit dependency on kotlin-reflect 1.4 to prevent strange errors
w: Some runtime JAR files in the classpath have an incompatible version. Consider removing them from the classpath
my build.gradle.kt:
plugins {
kotlin("jvm") version "1.4.21-2"
`java-gradle-plugin`
`maven-publish`
}
dependencies {
compileOnly(kotlin("stdlib-jdk8"))
compileOnly(kotlin("reflect"))
testImplementation("org.junit.jupiter:junit-jupiter-api:5.7.0")
testImplementation("org.junit.jupiter:junit-jupiter-engine:5.7.0")
}
repositories {
mavenCentral()
jcenter()
}
gradlePlugin {
plugins {
create("changed.this.for.this.post") {
id = "changed.this.for.this.post"
implementationClass = "changed.this.for.this.post.MyPlugin"
version = project.version
}
}
}
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile::class.java) {
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8.toString()
}
}
tasks.withType<Test> {
useJUnitPlatform()
}
You should use Gradle 6.8, it includes Kotlin 1.4.20.