不同的 Kotlin 版本在 Android 项目中。

huangapple go评论79阅读模式
英文:

different kotlin versions in android project

问题

Sure, here is the translated text:

我无法弄清楚如果在项目中和项目的依赖中有不同的Kotlin版本会出现什么问题。

选项1:

  • 项目包含Kotlin版本 1.3.72
  • 一些库(例如okhttp)包含Kotlin版本 1.4.10。 (我们现在在 Authenticator、Interceptor 等方面使用 Kotlin 1.4.x 的函数接口。)

选项2:

  • 项目包含Kotlin版本 1.4.0
  • 一些库包含Kotlin版本 1.3.71

在选项2中,我会得到以下警告:
w: 类路径中的运行时JAR文件应具有相同的版本。在类路径中找到了这些文件:
/.gradle/caches/transforms-2/files-2.1/ab41544fa06f7b55dec847efe3b9899c/jetified-kotlin-stdlib-jdk7-1.3.71.jar(版本1.3)
.gradle/caches/transforms-2/files-2.1/a4c6c3b949eb40b555dea1468ae75f87/jetified-kotlin-stdlib-1.4.10.jar(版本1.4)
.gradle/caches/transforms-2/files-2.1/f98f62bf33e752598311020043618780/jetified-kotlin-stdlib-common-1.4.10.jar(版本1.4)
w: 类路径中的某些运行时JAR文件具有不兼容的版本。考虑将它们从类路径中移除。

英文:

I can't figure out what problem I can get if I have different Kotlin versions in the project and in the dependencies of that project.

Option 1:

  • the project include Kotlin 1.3.72
  • some libraries (okhttp for example) include Kotlin 1.4.10. (We now use Kotlin 1.4.x functional interfaces for Authenticator, Interceptor, and others.)

Option 2:

  • the project include Kotlin 1.4.0
  • some libraries include Kotlin 1.3.71

In option 2 I get next warning:
w: Runtime JAR files in the classpath should have the same version. These files were found in the classpath:
/.gradle/caches/transforms-2/files-2.1/ab41544fa06f7b55dec847efe3b9899c/jetified-kotlin-stdlib-jdk7-1.3.71.jar (version 1.3)
.gradle/caches/transforms-2/files-2.1/a4c6c3b949eb40b555dea1468ae75f87/jetified-kotlin-stdlib-1.4.10.jar (version 1.4)
.gradle/caches/transforms-2/files-2.1/f98f62bf33e752598311020043618780/jetified-kotlin-stdlib-common-1.4.10.jar (version 1.4)
w: Some runtime JAR files in the classpath have an incompatible version. Consider removing them from the classpath

答案1

得分: 11

/.gradle/caches/transforms-2/files-2.1/ab41544fa06f7b55dec847efe3b9899c/jetified-kotlin-stdlib-jdk7-1.3.71.jar(版本1.3)

这可以通过在您的应用程序 build.gradle 依赖项中包含以下内容来解决:

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

此外,我个人建议添加以下依赖项以避免这些错误:

implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

另外,请确保在您的项目 build.gradle 中有 ext.kotlin_version = "1.4.10"

英文:

/.gradle/caches/transforms-2/files-2.1/ab41544fa06f7b55dec847efe3b9899c/jetified-kotlin-stdlib-jdk7-1.3.71.jar (version 1.3)

this can be resolved with including this in your app build.gradle dependencies:

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

Also, I have personally learned to add the following dependencies to avoid these errors:

implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

Also, make sure you have ext.kotlin_version = "1.4.10" in your project build.gradle

答案2

得分: 3

当差异不仅仅在次要发布版本(如1.3.70 / 1.3.72)之间,而是在1.3.x和1.4.x发布之间时,可能会出现哪些问题呢?您可能面临的风险包括,一个库可能会使用在新版本中更改了其签名的函数,从而导致运行时错误。这并不一定会发生,但是有可能发生(除非您确定您的依赖库不使用任何已更改的函数)。

英文:

What problems you can get? When the differences are not just in the minor release version (like 1.3.70 / 1.3.72) but are between a 1.3.x and a 1.4.x release, you risk e.g. that one library will use a function that has changed its signature in the new release, and so there will be a runtime error. This does not necessarily happen, but it can happen (unless you know for certain that your dependency libraries do no use any functions that have changed).

答案3

得分: 1

如果您的项目目标是Java 8,只需包含该Java版本的依赖项:

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"

如果您的目标是Java 6或7,遵循相同的规则。

您可以在这篇文章中详细了解更多信息:https://medium.com/@mbonnin/the-different-kotlin-stdlibs-explained-83d7c6bf293

英文:

If your project target Java 8 so just include the dependency on that Java version

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"

Follow the same rule if you target Java 6 or 7.

You clarify more about that in the post https://medium.com/@mbonnin/the-different-kotlin-stdlibs-explained-83d7c6bf293

huangapple
  • 本文由 发表于 2020年10月7日 15:21:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/64239149.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定