9

I switched over my Android project from 1.3.20 to 1.3.30 and I am suddenly getting following exceptions from some of the classes when they call hashCode() method. Note, I am getting this exception only on Android platform API 21 & 22, beyond Android API 24, everything works fine.

Caused by: java.lang.NoSuchMethodError: No static method hashCode(J)I in class Ljava/lang/Long; or its super classes (declaration of 'java.lang.Long' appears in /system/framework/core-libart.jar)

There is this thread that mentions similar symptoms but that was for Kotlin 1.2, I am wondering if anybody is encountering similar situation and if there is a workaround for this?

Subodh Nijsure
  • 3,305
  • 5
  • 26
  • 45

2 Answers2

3

As an alternative, you may set a JVM target for Kotlin compilation to "1.6", as Kotlin 1.3.30 has started to infer the JVM target from the Java version in android.compileOptions and chooses "1.8" if both sourceCompatibility and targetCompatibility are set to that or higher.

In the module's build.gradle, add:

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
    kotlinOptions {
        jvmTarget = '1.6'
    }
}

There will be no need to do this once the issue in D8 desugaring is fixed.

This issue is tracked in the Kotlin issue tracker as KT-31027.

hotkey
  • 140,743
  • 39
  • 371
  • 326
1

This is related to this issue - https://issuetracker.google.com/issues/129730297 so solution seems to be to upgrade to latest AGP!

Subodh Nijsure
  • 3,305
  • 5
  • 26
  • 45