Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why Kotlin plugin adds kotlin-stdlib-jre7 (not kotlin-stdlib) reference for Android project

Android Studio 2.3.3; Kotlin Plugin: 1.1.4; Kotlin Compiler: Kotlin to JVM: 1.6.

Android Studio > New Project > Configure Kotlin in Project action adds reference for kotlin-stdlib-jre7 to gradle file. I would expect kotlin-stdlib as we Kotlin target JVM is 1.6.

Have not found good explanation. E.g. this answer states that

The kotlin-stdlib-jre7 artifact is not supposed to work on Android, which currently supports only Java 6 platform. When targeting Android, you should use kotlin-stdlib, which is built for JRE 6

like image 624
user2051551 Avatar asked Aug 30 '17 07:08

user2051551


1 Answers

Android supports Java 7 for some years already. In fact, partial support for Java 8 is on the way, at the beginning by means of Jack toolchain and currently by means of desugaring in the default toolchain.

So, kotlin-stdlib-jre7 is perfectly fine.

As you can see in this answer, kotlin-stdlib got two additional extension libraries kotlin-stdlib-jre7 and kotlin-stdlib-jre8 in 1.1. This libraries add specific features for Java 7 and Java 8, and include kotlin-stdlib as a transitive dependency. See also the Kotlin 1.1 release notes:

Java 8 standard library support

There are now separate versions of the standard library supporting the new JDK APIs added in Java 7 and 8. If you need access to the new APIs, use kotlin-stdlib-jre7 and kotlin-stdlib-jre8 maven artifacts instead of the standard kotlin-stdlib. These artifacts are tiny extensions on top of kotlin-stdlib and they bring it to your project as a transitive dependency.

Kotlin plugin in current versions of Android Studio add kotlin-stdlib-jre7 as a dependency when configuring Kotlin in the project, as Android Studio and build tools support Java 7 in a backward compatible way since Android Studio 0.3.2, released in October 2013. See also Does Android support JDK 6 or 7. Specifically, release notes state:

The main feature in this release is support for Android KitKat:

Support for language features like the diamond operator, multi-catch, try-with-resources, strings in switches, etc. When creating a new project, you can specify a source language level:

And:

Note that you can use all these language features not just with Android KitKat, but with older versions of Android too! There is one exception to that: try-with-resources, which will require minSdkVersion 19.

like image 111
Xavier Rubio Jansana Avatar answered Jan 13 '23 11:01

Xavier Rubio Jansana