Unable to load class 'org.jetbrains.kotlin.config.LanguageVersion'
Asked Answered
N

5

10

When I bought the new laptop, to copy my android studio projects from old laptop to new laptop, I just copied all the projects from the folder AndroidStudioProjects to respective folder in new laptop.

Usually it used to work. But this time, I am getting a new error while gradle sync.

When I try to run a copied project, in the process of gradle sync, I am getting following error.

Unable to load class 'org.jetbrains.kotlin.config.LanguageVersion'.

This is an unexpected error. Please file a bug containing the idea.log file.

and

org/jetbrains/kotlin/config/LanguageVersion
> org.jetbrains.kotlin.config.LanguageVersion

* Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Exception is:
java.lang.NoClassDefFoundError: org/jetbrains/kotlin/config/LanguageVersion
    at org.jetbrains.kotlin.gradle.plugin.sources.FragmentConsistencyChecks.<init>(ConsistencyChecker.kt:24)
    at org.jetbrains.kotlin.gradle.plugin.sources.DefaultKotlinSourceSetKt.<clinit>(DefaultKotlinSourceSet.kt:210)
    at org.jetbrains.kotlin.gradle.plugin.sources.DefaultKotlinSourceSet.<init>(DefaultKotlinSourceSet.kt:62)
    at org.jetbrains.kotlin.gradle.plugin.sources.DefaultKotlinSourceSetFactory.doCreateSourceSet(KotlinSourceSetFactory.kt:162)
    at org.jetbrains.kotlin.gradle.plugin.sources.DefaultKotlinSourceSetFactory.doCreateSourceSet(KotlinSourceSetFactory.kt:65)
    at org.jetbrains.kotlin.gradle.plugin.sources.KotlinSourceSetFactory.create(KotlinSourceSetFactory.kt:30)
    at org.jetbrains.kotlin.gradle.plugin.sources.KotlinSourceSetFactory.create(KotlinSourceSetFactory.kt:23)


//I have trimmed the stack trace.

Caused by: java.lang.ClassNotFoundException: org.jetbrains.kotlin.config.LanguageVersion
    ... 230 more

Not only by copying from other laptop to new laptop, even when I try to fetch the full project from version control, I am getting the same error.

There is not enough resources available online for it.

Any help would be appreciated.

Nada answered 17/1, 2022 at 1:50 Comment(0)
A
26

Maybe you are using too old com.google.devtools.ksp for kotlin 1.8.10. Try to update it to version 1.8.21-1.0.11:

id("com.google.devtools.ksp") version "1.8.21-1.0.11" apply false

I encountered such a problem

Airtight answered 27/12, 2023 at 4:18 Comment(0)
T
5

I have the same problem today and solved it by changing the Gradle user home.

This build error happens when the Gradle files have broken.

You can change the Gradle user home from

'Settings' -> 'Build, Execution, Deployment' -> 'Build Tools' -> 'Gradle'

After resetting the Gradle user home directory, the Gradle will re-download the necessary files to build the project. It should work after the re-download and re-initiate the Gradle files in the user home directory.

Twandatwang answered 7/11, 2022 at 9:32 Comment(1)
Deleting the gradle folder and reopening the project in IntelliJ will cause IntelliJ to redownload the required gradle files, which solved the problem for me:)Codon
R
0

I encountered this issue and followed the instructions below to ensure my project was configured to support Kotlin. It turns out Kotlin was not a dependency of mine.

https://capacitorjs.com/docs/plugins/android#using-kotlin

Once that is done, the following will have been added to build.gradle:

classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

$kotlin_version can be defined at the top of the buildscript, so it looks something like this:

buildscript {
    ext.kotlin_version = '1.7.0'

    repositories {
        ...
    }
    dependencies {
        ...
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        ...
    }
}
Reflection answered 26/6, 2022 at 15:3 Comment(0)
G
0

At build.gradle in project folder,

update KSP version. That is before the dash (-)

Example, if using Kotlin 2.0.0

then the version is 2.0.0 dash...

id("com.google.devtools.ksp") version "2.0.0-1.0.24" apply false

According to the Kotlin KSP FAQ:

"If the language version is the same, Kotlin compiler is supposed to be backward compatible. Bumping Kotlin compiler should be trivial most of the time. If you need a newer KSP implementation, please upgrade the Kotlin compiler accordingly."

This suggests that while the Kotlin compiler is generally backward compatible if the language version remains unchanged, using a newer KSP implementation may require upgrading Kotlin.

Gumbo answered 3/9, 2024 at 0:14 Comment(0)
C
-2

Run this command in Terminal

./gradlew clean

Then Run [File - from android studio menu]

File-> Invalidate caches and restart
Cornuted answered 17/1, 2022 at 2:47 Comment(2)
Tried those. Didn't help.Nada
People need to understand that invalidating caches and cleaning is not always the solutionDropper

© 2022 - 2025 — McMap. All rights reserved.