Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kotlin runtime jar vs kotlin stdlib jar

Tags:

kotlin

What's the difference between kotlin-runtime.jar (225.1K) and kotlin-stdlib.jar (727.3K) (sizes are for 1.0.0-beta-1103 version)? Which one should I distribute with my application? For now I live with kotlin-stdlib.jar, because that's what Android Studio generated, but I wonder if I can use kotlin-runtime.jar since it's smaller.

like image 827
Yaroslav Avatar asked Oct 30 '15 06:10

Yaroslav


People also ask

Is Kotlin Stdlib needed?

Currently, there is no need for a special standard library artifact for JDK 11 because Kotlin doesn't provide any APIs depending on it.

What is Kotlin Stdlib?

Kotlin Standard Library. The Kotlin Standard Library provides living essentials for everyday work with Kotlin. These include: Higher-order functions implementing idiomatic patterns (let, apply, use, synchronized, etc). Extension functions providing querying operations for collections (eager) and sequences (lazy).

What is Kotlin runtime?

The Kotlin “runtime” is just a plain old Java library which only does anything if a Java runtime is around to do something with it. Kotlin code relies on the Kotlin “runtime” library. Therefore, JRE + Kotlin JAR = running Kotlin code. No other native binaries needed.


1 Answers

The runtime library only contains base Kotlin language types required to execute compiled code. It is a minimal classes set required.

The standard library contains utility functions you need for comfortable development. These are such functions for collections manipulations, files, streams and so on.

In theory you can use just runtime but you generally shouldn't because there are no standard library in it so you will lose many utility functions required for comfortable development (such as map, filter, toList and so on) so I don't think you should.

So in fact you need both. If you need make the result package smaller then you can process you app with proguard.

Update

Starting from Kotlin 1.2, kotlin-runtime and kotlin-stdlib are merged into single artifact kotlin-stdlib.

We merge kotlin-runtime and kotlin-stdlib into the single artifact kotlin-stdlib. Also we’re going to rename kotlin-runtime.jar, shipped in the compiler distribution, to kotlin-stdlib.jar, to reduce the amount of confusion caused by having differently named standard library in different build systems. That rename will happen in two stages: in 1.1 there will be both kotlin-runtime.jar and kotlin-stdlib.jar with the same content in the compiler distribution, and in 1.2 the former will be removed.

Refer to Kotlin 1.1: What’s coming in the standard library for details.

like image 62
Sergey Mashkov Avatar answered Oct 07 '22 16:10

Sergey Mashkov