gpt4 book ai didi

android - 为什么 Kotlin 插件为 Android 项目添加 kotlin-stdlib-jre7(不是 kotlin-stdlib)引用

转载 作者:IT老高 更新时间:2023-10-28 13:42:18 38 4
gpt4 key购买 nike

Android Studio 2.3.3; Kotlin 插件:1.1.4; Kotlin 编译器:Kotlin 到 JVM:1.6。

Android Studio > 新建项目 > 在项目操作中配置 Kotlin 添加kotlin-stdlib-jre7 到 gradle 文件的引用。我希望 kotlin-stdlib 因为我们的 Kotlin 目标 JVM 是 1.6。

还没有找到好的解释。例如。 this answer声明

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

最佳答案

Android 已经支持 Java 7 好几年了。事实上,对 Java 8 的部分支持正在进行中,一开始是通过 Jack toolchain,现在是通过 desugaring in the default toolchain

所以,kotlin-stdlib-jre7 完全没问题。

正如您在 this answer 中看到的,kotlin-stdlib 有两个额外的扩展库 kotlin-stdlib-jre7kotlin-stdlib-jre8在 1.1 中。该库为 Java 7 和 Java 8 添加了特定功能,并包含 kotlin-stdlib 作为传递依赖项。另请参阅 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.

当前版本的 Android Studio 中的 Kotlin 插件在项目中配置 Kotlin 时添加 kotlin-stdlib-jre7 作为依赖项,因为 Android Studio 和构建工具从 Android Studio 0.3.2, released in October 2013 开始以向后兼容的方式支持 Java 7 .另请参阅 Does Android support JDK 6 or 7 。具体来说,发行说明指出:

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:

还有:

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.

关于android - 为什么 Kotlin 插件为 Android 项目添加 kotlin-stdlib-jre7(不是 kotlin-stdlib)引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45954974/

38 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com