I'm making a private Kotlin Multiplatform library that will be in a private repo hosted on Bitbucket.
My library depends on another library, called Krypto.
So, naturally, I have the following dependency in the common module of the library:
val commonMain by getting {
dependencies {
api("com.soywiz.korlibs.krypto:krypto:2.2.0")
}
}
Now, when I import the library via Cocoapods to an iOS project, it works perfectly fine. However when I insert the .jar file to my Android project as a dependency:
implementation files('libs/MyLibrary-jvm-1.0.0.jar')
it compiles, but at runtime crashes with the following error:
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/soywiz/krypto/SHA256Kt
If I add the Krypto dependency to my Android project, everything works fine, however I would like the dependencies to be already included in my library. How to do that?
I also tried adding the java-library plugin and adding the dependency in a java build block, but it didn't change anything.
The solution was in the documentation all along... https://kotlinlang.org/docs/multiplatform-build-native-binaries.html#export-dependencies-to-binaries
In the Gradle configuration of the binaries of a specific platform we need to use export() to include dependencies. To also include dependencies of the dependencies, we need to do export(dep, transitiveExport = true).
kotlin {
sourceSets {
commonMain by getting {
dependencies {
api(project(":dependency"))
}
}
}
java().binaries {
framework {
export(project(":dependency"), transitiveExport = true)
}
}
}