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

Viewed 1026

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.

2 Answers

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"
        ...
    }
}

Run this command in Terminal

./gradlew clean

Then Run [File - from android studio menu]

File-> Invalidate caches and restart
Related