'kotlin unit was compile with an incompatible version of 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


Solution 1:[1]

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Muhammad Rio