Android Studio中过时的Kotlin运行时警告

Outdated Kotlin Runtime warning in Android Studio

下载并安装了最新的Kotlin插件后,我收到了来自Android Studio的过时Kotlin运行时警告,告诉我:

Your version of Kotlin runtime in 'kotlin-stdlib-1.1.2' library is
1.1.2, while plugin version is 1.1.2-release-Studio2.3-3. Runtime library should be updated to avoid compatibility problems.

我试图单击"更新运行时"按钮,但又收到另一条消息:

Automatic library version update for Gradle projects is currently
unsupported. Please update your build.gradle manually.

如何解决这个问题?


您可以在项目级别build.gradle文件中更新Kotlin版本。如果按常规方式配置了它,则顶部应该有以下一行:

1
ext.kotlin_version = '1.1.2'

要升级到与您的插件匹配的版本,只需将此行更改为:

1
ext.kotlin_version = '1.1.2-3'

编辑(以回答以下问题):

该错误告诉您需要升级您的版本,问题是在哪里可以找到必须放入1.1.2-3而不是例如说1.1.2-release-Studio2.3-3

找出Kotlin最新版本的最佳方法是访问kotlinlang.org并寻找"最新版本"。应该在首页上。

如果版本号很重要,则要做的另一件事是检查托管版本的存储库。对于Android,您可能会从jcenter获得它,可以在其中找到存储库页面,其中列出了所有可用版本。

您还可以通过转到此处浏览实际托管文件的jcenter的原始Maven存储库,或在mvnrepository或mavencentral(此处为后者的原始版本)上查找Kotlin。


在您的(Project: [projectName]) build.gradle文件中找到以下内容:
ext.kotlin_version = 'x.x.x'并将x.x.x替换为当前版本的Kotlin插件。
enter image description here

为了检查哪个是您的Kotlin插件的当前版本:

  • 转到:工具-> Kotlin-> Confugure Kotlin插件更新

  • 点击"再次检查"。一秒钟后,您将看到Kotlin插件的版本。 (如果不是最新的,您的Kotlin插件将被更新。)
    enter image description here
    enter image description here

  • N.B .:同时检查您的(Module: app) build.gradle文件,并确保不使用:

    1
    compile"org.jetbrains.kotlin:kotlin-stdlib-jre7:1.2.21"

    1
    compile 'org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.2.40'

    注意区别" ... jre7 ..."->" ... jdk7 ..."。另外,用您当前的Kotlin插件版本替换" 1.2.40"。


    它抱怨(在Android Studio 3.0.1上)...很可能是由于所引用库的依赖关系引起的:

    Your version of Kotlin runtime in 'org.jetbrains.kotlin:kotlin-stdlib:1.1.3@jar' library is 1.1.3, while plugin version is 1.1.51-release-Studio3.0-1.

    然后在模块级别build.gradle中,根据要求的版本强制构建:

    1
    2
    3
    configurations.all() {
        resolutionStrategy.force 'org.jetbrains.kotlin:kotlin-stdlib:1.1.51'
    }

    结果是:

    1
    2
    3
    4
    ./gradlew app:dependencies | grep kotlin
    Download https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-stdlib/1.1.51/kotlin-stdlib-1.1.51.pom
     |    |    +--- org.jetbrains.kotlin:kotlin-stdlib:1.1.3 -> 1.1.51
     ...

    您可能需要更新两部分:

  • 项目的kotlin运行时
  • kotlin插件
  • Ivo Stoyanov的答案显示了如何使用android studio菜单执行此操作。当我收到错误消息并尝试尝试此操作(更新kotlin插件)时,它仍然抱怨kotlin运行时。您可以在每个项目的基础上进行更新,方法是将ext.kotlin_version上的行添加到项目构建gradle,如其他一些答案所示。但是您需要为此了解kotlin运行时版本。另外,您也可以通过菜单进行操作,如下所示,这是android studio向您显示可用版本的好处,并且您可以选择最新版本。

    step 1

    step 2

    step 3

    step 4

    然后android studio将在您的项目构建gradle中添加适当的行。


    将您的ext.kotlin_version从'1.1.2-4'更改为ext.kotlin_version ='1.1.2-5'为我解决了问题


    截至2019年3月8日,当前的kotlin版本为'1.3.21'

    build.gradle

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    buildscript {
       ext.kotlin_version = '1.3.21'
       repositories {
          google()
          jcenter()
       }
       dependencies {
          classpath 'com.android.tools.build:gradle:3.3.2'
          classpath"org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }

    干杯


    the latest version of kotlin is 1.2.41 use this and syn your project.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    buildscript {
    ext.kotlin_version = '1.2.41'
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.2'
        classpath"org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
    }


    搜索这两行代码

    ext.kotlin_version ='1.3.11'

    类路径" org.jetbrains.kotlin:kotlin-gradle-plugin:$ kotlin_version"

    将$ kotlin_version替换为实际值(此处为1.3.11)

    类路径" org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.11"

    之后,您的IDE会自动为您建议更新的版本

    快乐的编码:)


    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    buildscript {
        ext.kotlin_version = '1.2.50'
        repositories {
            google()
            jcenter()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:3.1.2'
            classpath"org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

            // NOTE: Do not place your application dependencies here; they belong
            // in the individual module build.gradle files
        }
    }

    当您更新从android studio弹出的kotlin插件版本时,就会出现此问题,但问题是Android Studio的当前版本无法动态更改位于项目级别Build.gradle文件中的kotlin gradle插件。

    1
    2
    3
    dependencies {
         classpath"org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.10"
    }

    How to solve this issue?

    因此,您需要手动更改此版本,您可以在此处找到


    我的Android Studio从3.0.1升级到3.2.1之后,我遇到了同样的问题。

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    buildscript {
    ext.kotlin_version = '1.2.51'
    repositories {
        google()
        jcenter()
        mavenCentral()
        maven { url"https://jitpack.io" }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
        classpath"org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }

    }


    有点烦人,但工作室有时会喜欢。以下步骤可以解决此问题。

    设置->构建,执行,开发-> Gradle->使用默认的Gradle包装器(推荐)

    将其更改为"使用本地",然后再更改为"使用默认值"。在关闭设置窗口后,Studio会询问有关更新gradle的信息。


    Kotlin最新版本:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    buildscript {
        ext.kotlin_version = '1.2.41'

        repositories {
            google()
            jcenter()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:3.0.1'
            classpath"org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
            classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
            classpath 'com.google.gms:google-services:1.5.0-beta2'


            // NOTE: Do not place your application dependencies here; they belong
            // in the individual module build.gradle files
        }
    }


    我在Android Studio和IDEA中多次遇到此问题,发现如果您将项目设置为Gradle文件,并且将依赖项的kotlin-gradle-plugin版本设置为$kotlin_version,则在依赖项中,警告消息将告诉您您需要将ext.kotlin_version设置为哪个版本。

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    buildscript {
    ext.kotlin_version = '1.2.40'
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.2'
        classpath"org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
    }

    enter image description here


    我在Canary频道的最新Android Studio上遇到了这个问题。您可能还需要考虑将Android Studio降级为稳定版本。

    这是我在Android Studio 3.0 RC1上发生的。