6

I'm using org.jetbrains.kotlin:kotlin-reflect library in my project (included in gradle dependencies).

The app has been working without any problems however after upgrading android gradle plugin to newest version 3.1.0 the app started to crash on one device (Nexus 5, Android 4.4.3). The logs are as follows:

E/AndroidRuntime: FATAL EXCEPTION: kotlin.jvm.KotlinReflectionNotSupportedError: Kotlin reflection implementation is not found at runtime. Make sure you have kotlin-reflect.jar in the classpath at kotlin.jvm.internal.ClassReference.error(ClassReference.kt:86) at kotlin.jvm.internal.ClassReference.getSimpleName(ClassReference.kt:23)

I assume it's not expected behaviour, but maybe someone found a workaround/solution?

For now I was forced to downgradle android gradle plugin to 3.0.1 to prevent app from crashing.

====================

I've tried to recreate environment causing the crash, however I did not manage to reproduce the crash. Because this happens only on older android versions (pre-L) and after upgrading android gradle plugin that introduces some dex optimisations, my guess is that it's somehow related.

====================

For those marking this issue as duplicate:

I'm not sure if can be more clear about that: other ticket is about missing dependency. I have kotlin-reflect dependency in my build.gradle. Moreover my app works on higher Android versions as well as after downgrading the android gradle plugin to 3.0.1. With missing dependency this would not work with any version of android gradle plugin. Therefore the answer from other question is not valid for this one.

Marcin Bak
  • 1,410
  • 14
  • 25
  • 1
    @Zoe This is not the case, the kotlin-reflect dependency is there, and the app works perfectly, but crashes only after upgrading to android build gradle plugin 3.1.0 and only on one device. – Marcin Bak Mar 28 '18 at 12:44
  • Post your `build.gradle` files. – Jared Burrows Apr 01 '18 at 22:47
  • 1
    This is not a duplicated issue. The solution on the other question does not solve this problem. It is addressed to android gradle plugin 3.1.0 and the only way to fix it was downgrading to 3.0.1 – Leandroid Apr 03 '18 at 11:14
  • 1
    @JaredBurrows unfortunately cannot paste the failing build.gradle as it's part of a company's project. For sure it is not a duplicate, if you read the question and my comment and compare it to linked issue you'll notice that I specifically stated that I include the dependency in the code. Moreover the code works on devices with higher android versions and works after downgrading gradle plugin version. – Marcin Bak Apr 03 '18 at 19:15

1 Answers1

4

Adding line togradle.properties fixes the problem:

android.enableD8MainDexList=false

Additionally, bug seems to be gone in plugin version 3.2.0-alpha11

Sources:

jskierbi
  • 1,635
  • 1
  • 14
  • 22