Mikhail
Mikhail

Reputation: 808

Kotlin runtime error kotlin.Any is not found

I have a multi-module project. With the same build, the apk's size may differ by 300KB (from 17 to 17.3MB). In the build with 17MB in runtime I get an error:

java.lang.AssertionError: Built-in class kotlin.Any is not found.

Also in the project, obfuscation is configured. But I don’t think it’s caused by this. Clean and Invalidate and Restart do not always help.

Upvotes: 8

Views: 2742

Answers (3)

karl
karl

Reputation: 1109

If you want the smaller build, you'll need to live without reflection. It was separated out because it was so big and not everyone needs it.

If you have to have the reflection in there, and you are in a multi-module project (Java 9 Jigsaw module stuff), you will need to include kotlin.reflect in your module-info.java file:

module your.module.pkg{
  requires kotlin.stdlib;
  requires kotlin.reflect;
  exports your.module.pkg;
}

... as well as your org.jetbrains.kotlin:kotlin-stdlib and kotlin-reflect dependencies in your gradle build file or maven pom.xml.

Upvotes: 1

Eric
Eric

Reputation: 17536

although you said restarting doesn't work, it's the only thing that works for me consistently:

  1. restart Android Studio: File > Invalidate Caches / Restart... > Just Restart
  2. build & run the app again: Shift + F10

...but then the problem comes back again a few builds later.

Upvotes: -1

katie
katie

Reputation: 216

I encountered this issue, made sure Kotlin stdlib and reflect libraries have the same version, updated Gradle to make sure its not the build too, tried different Kotlin versions as well, but nothing worked. Eventually, I found out that my packageOptions is excluding a Kotlin folder

packagingOptions {
  exclude '**/kotlin/**'
}

Have no idea why this code was there, but removing it solves the problem for me! So definitely check your packageOptions in your module-level build.gradle file.

Upvotes: 3

Related Questions