Home > Back-end >  Kotlin module problem that turns into java noClassDefFoundError
Kotlin module problem that turns into java noClassDefFoundError

Time:08-25

When building my project in Android Studio, I get the following error.

Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.5.1, expected version is 1.1.16.

I have tried changing the Kotlin version in my project-level gradle file to almost every single stable release available without much success. The one or two stable releases of Kotlin that do make this error go away generate their own errors.

The current Gradle version 5.6.4 is not compatible with the Kotlin Gradle plugin. Please use Gradle 6.1.1 or newer, or the previous version of the Kotlin plugin.

jav.lang.noClassDefFoundError

Build file 'C:\Users\pictu\Downloads\ble-starter-android-master\ble-starter-android-master\app\build.gradle' line: 18

A problem occurred evaluating project ':app'.
> org/gradle/api/services/BuildService

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

* Exception is:
org.gradle.api.GradleScriptException: A problem occurred evaluating project ':app'.
    at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:93)
    at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl$2.run(DefaultScriptPluginFactory.java:227)
    at

...


org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:91)
    ... 130 more
Caused by: java.lang.ClassNotFoundException: org.gradle.api.services.BuildService
    ... 160 more

I've tried using multiDex, I've tried changing the Kotlin version, I've tried changing the compileSdkVersion minSdkVersion targetSdkVersion, but none of them worked. I've also looked at several SO posts, but I haven't found any that help my specific issue.

UPDATE 1: The error message points out this line specifically.

apply plugin: 'kotlin-android'

UPDATE 2: The answer to this SO post helped me get a little further. Now I am getting this cryptic stack trace that mentions something about a circular reference. I haven't been able to find out what a circular reference is in this context.

Invoke-customs are only supported starting with Android O (--min-api 26)
Stack trace:
com.android.tools.r8.a: Invoke-customs are only supported starting with Android O (--min-api 26)
    at com.android.tools.r8.dex.r.a(:289)
    at com.android.tools.r8.dex.r.a(:98)
    at com.android.tools.r8.dex.r.b(:188)
    at com.android.tools.r8.dex.b.a(:63)
    at 

...

    Caused by: [CIRCULAR REFERENCE: com.android.tools.r8.a: Invoke-customs are only supported starting with Android O (--min-api 26)]

CodePudding user response:

These are the two Stack Overflow posts that led me to my answer (1, 2).

You need to update your Gradle settings. I updated mine to Gradle version 6.1.1 using the chart in the answer to the first SO post I referenced.

The second thing you need to do is specify sourceCompatibility and targetCompatibility as JavaVersion.VERSION_1_8 in the compileOptions section of the app level Gradle file.

  • Related