Is it even possible to use Kotlin to write a library?
The problem I see is that it will depend on specyfic versions of kotlin-stdlib and kotlin-runtime and force user of the library to use the same version.
I'm considering using jarjar to repackage those but then, how to include those in a fatjar-type distribution? Inside the unpacked aar I see /libs directory - is there a way to use that?
As per the comments, there are several
.aarlibraries available that are written in Kotlin such as MapMe.Indeed there is a curated list of such libraries in this GitHub repo
You can see by examining the
build.gradlefor the same that these do include a dependency onkotlin-stdlib.This is not a lightweight dependency: the
.jarsize is approx 1MB. And if you make a blank project, compile the.apk, and upload it to a method count site it comes to6086methods.However, if the consuming project already uses Kotlin they will already have bourne the burden of the extra classes. Since they will have explicitly included
kotlin-stdlibas a dependency in theirbuild.gradleit will probably force resolution of the dependency in your library to their version. This is unlikely to cause problems withstdlib.Even if the consumer is not using Kotlin in their project, aggressive use of Proguard can eliminate unused methods. The official Kotlin website explains:
The source for the second statement is a blog post on Medium so your mileage may vary.