Adding Kotlin runtime library to aar in android

WHAT I WANT :smile: :

  • building kotlin library,
  • deliver it as an .aar file
  • Java project that uses my .aar don’t need configure anything, just include my .aar and start playing.

first Q : IT THAT EVEN Possible ? cause i’m loosing hope :smile:

if the project that uses my library doesn’t have Kotlin configured, then it says ClassNotFoundException.


if kotlin have the same byte code as Java byte code, (and 100% compatible),

then why i need to have kotlin when using .aar writen in kotlin in a JAVA Project ?

After some reaserch, i discovered that i must include kotlin runtime library in my project but i don’t know how,
i’ve allready tried basically all the solution overs the net ,

i think fat aar isn’t supported on Android,

Thank You All for your attention.

in my aar project i have a module with the following build.gradle

apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-android' 


dependencies {

    api "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"


in my application that uses the .aar
i have the following in project build.gradle

 dependencies {
        classpath ''

in the build.gralde module

    implementation(name: 'my-aar-library', ext: 'aar')

and when i run the app, it crash and here is the stack :

09-25 15:14:22.814 3239-3239/com.example.mymodule E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.mymodule, PID: 3239
    java.lang.NoClassDefFoundError: kotlin.jvm.internal.Intrinsics
        at .

PS :

clearly i must add the kotlin runtime-library to my .aar
i tried all over the net, it doesn’t work :sob: :sob: :sob: :sob: :sob: :sob:

The reason is that bytecode is nothing without a standard library. Even if you don’t explicitly call the Kotlin library (but use the Java library only) the compiler will generate invocations into the Kotlin standard library for checks etc. However, if you remove the dependency from your Kotlin project it will not be in the AAR either, but may not compile (there are some flags that prevent many of the checks to be generated).

1 Like