【问题标题】:How to set Kotlin version如何设置 Kotlin 版本
【发布时间】:2022-07-20 15:04:07
【问题描述】:

您好,我在构建 https://github.com/jitsi/jitsi-meet 的 android 部分时遇到以下错误

'let((T) -> R): R' 仅从 Kotlin 1.3.50 开始可用,不能在 Kotlin 1.3 中使用

在线Screen.kt#L156

在 Android Studio 设置中显示在编译器设置中使用 Kotlin 1.6,当我将 build.gradle 中的项目变量 kotlinVersion 设置为 1.6.10 时,我仍然遇到相同的错误。

【问题讨论】:

  • 你为什么不尝试为链接使用关键字而不是随机粘贴呢?它使它看起来很拥挤。您可以通过这种方式使用它 -> [您的文字在此处](yourUrlHere)。这是一个示例测试 -> Click here to open stackoverflow

标签: android react-native kotlin jitsi


【解决方案1】:

根据代码库,我观察到react-native-screens 项目正在使用Kotlin 进行开发。而在您的项目中,您是在纯 Java 中实现您的项目。

因此,要使用此库,您需要在项目中添加 kotlin 支持。为此,请在your project level build.gradle中添加以下代码sn-p

  1. buildscriptdependencies 块中添加 kotlin 类路径:
// Project build.gradle file.
buildscript {
    ext.kotlin_version = '1.4.10'
    ...
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}
  1. 然后通过在所需模块的build.gradle 文件中添加以下内容,将kotlin-android 插件应用到所有所需模块。
plugins {
    ...
    id 'kotlin-android'
}

您可以在 react-native-screens build.gradle Line 12react-native-screens build.gradle Line 23 的库中找到相同的实现。

参考:https://developer.android.com/kotlin/add-kotlin

【讨论】:

  • 你为什么不尝试为链接使用关键字而不是随机粘贴呢?它使它看起来很拥挤。您可以通过这种方式使用它 -> [您的文字在此处](yourUrlHere)。这是一个示例测试 -> Click here to open stackoverflow
  • @Sambhav.K 更新了评论。感谢您的反馈。 :)
  • 好的。现在好多了。但底部的链接也可以缩短
  • 我试过了,但它说找不到apply plugin: 'kotlin-android',但是当我把它改成apply plugin: 'kotlin'它说The 'java' plugin has been applied, but it is not compatible with the Android plugins.
  • OK 只有应用第一步才有效。
【解决方案2】:

更新android/build.gradle如下:

{
  buildscript {
    ext {
      ...
      kotlinVersion = "1.5.31"
  }
   dependencies { 
  [enter image description here][1] classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.31"
}

} }

【讨论】:

    猜你喜欢
    • 2017-12-22
    • 2022-06-13
    • 2013-11-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-22
    • 1970-01-01
    • 2019-04-14
    相关资源
    最近更新 更多