fwcd / kotlin-language-server

Kotlin code completion, diagnostics and more for any editor/IDE using the Language Server Protocol
MIT License
1.62k stars 203 forks source link

Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin #457

Open raxod502 opened 1 year ago

raxod502 commented 1 year ago

I have a working Android project (that is, ./gradlew build builds an apk file that can be installed and run) which is written in Kotlin. When I open the project in Emacs with LSP using kotlin-language-server, I receive the following diagnostic on every line of code:

Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.8.0, expected version is 1.6.0.
The class is loaded from /home/raxod502/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.8.20/e72fc5e03ec6c064c678a6bd0d955c88d55b0c4a/kotlin-stdlib-1.8.20.jar!/kotlin/Unit.class

I checked Editor integration and Troubleshooting but did not see any relevant tips. I also searched the issue tracker but found only https://github.com/fwcd/kotlin-language-server/issues/198#issuecomment-1367081783 as a reference, which doesn't seem relevant in this case.

Here's my build.gradle.kts:

plugins {
    id("com.android.application") version "7.4.2"
    id("org.jetbrains.kotlin.android") version "1.8.20"
}

repositories {
    google()
    mavenCentral()
}

android {
    compileSdkVersion(32)
    namespace = "redacted"
    defaultConfig {
        applicationId = "redacted"
        minSdkVersion(16)
        targetSdkVersion(32)
        versionCode = 1
        versionName = "0.1.0"
    }
    buildTypes {
        getByName("release") {
            isMinifyEnabled = false
        }
    }

    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_17
        targetCompatibility = JavaVersion.VERSION_17
    }
}

dependencies {
    implementation("androidx.appcompat:appcompat:1.2.0")
    implementation("com.google.android.material:material:1.2.0")
    implementation("androidx.constraintlayout:constraintlayout:2.0.4")
}

I don't, to my knowledge, have Kotlin installed globally on my system. The only place it's installed is via Gradle in this project, where the version is specified in build.gradle.kts as 1.8.20. I am not sure where this other 1.6.0 version number is coming from that is being referenced by kotlin-language-server.

If it would help in diagnosing the issue, I am happy to provide a sample project that reproduces the issue, or relevant logs.

raxod502 commented 1 year ago

Maybe the version of Kotlin used by kotlin-language-server is hardcoded to 1.6.0 and I need to upgrade to a build from source as https://github.com/fwcd/kotlin-language-server/pull/414 has not made it into a release yet? (If so, would be great to document the supported Kotlin versions somewhere; I had assumed all versions were supported.)

raxod502 commented 1 year ago

Followed the instructions in Building and with that version the error no longer occurs. Would be great to have this documented. I'm happy to help if that would be handy.

themkat commented 1 year ago

This is sadly a known issue. ~Only one person is able to do releases, and they are super busy with other things.~ I guess those of us who are fairly active here was hoping that we would get a new release, to avoid this issue being posted many times both here and in the VSCode plugin repo 🙁 Hopefully we can get the automatic releases PR merged soon 🙂

433 is a PR that will fix automatic releases on merges to main. That PR is only waiting for one specific comment to be resolved before merging. Hopefully also for @fwcd to address the requested changes.

EDIT: Seems I have rights to push tags now (failed last time I tried), but the release pipeline is broken...

themkat commented 1 year ago

A new version was released last night! 😄 (thank you @fwcd !!!). This will probably be resolved by using that newest version.