Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kotlin-reflect and android gradle plugin 3.1.0

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.

like image 920
Marcin Bak Avatar asked Mar 28 '18 12:03

Marcin Bak


1 Answers

Adding line togradle.properties fixes the problem:

android.enableD8MainDexList=false

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

Sources:

  • https://www.reddit.com/r/androiddev/comments/7ss81w/android_studio_31_canary_9_is_now_available/dt7t0s2/
  • https://issuetracker.google.com/issues/72039872
like image 129
jskierbi Avatar answered Oct 12 '22 03:10

jskierbi