android - 警告 "Kotlin plugin version is not the sam

我有一个 Android 工作室项目,我在其中添加了一个 Java 库模块,我称之为 core。我的三个 Gradle 构建文件如下所示。

项目/build.gradle

buildscript {
    ext.kotlin_version = '1.2.40'
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

核心/build.gradle

apply plugin: 'java-library'
apply plugin: 'kotlin'

dependencies { 
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7"
    ...
}

app/build.gradle

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android { ... }

dependencies {
    implementation project(':core')
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.android.support.constraint:constraint-layout:1.1.0'
    implementation 'com.android.support:appcompat-v7:27.1.1'

    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
    testImplementation 'junit:junit:4.12'
}

我遇到的问题是,在 core/build.gradle 中,kotlin-stdlib-jdk7 行给了我警告 Plugin version (1.2 .40)与库版本(jdk7-1.2.40)不同。我已尝试将其更改为:

实现“org.jetbrains.kotlin:kotlin-stdlib”

实现“org.jetbrains.kotlin:kotlin-stdlib:1.2.40”

实现“org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.2.40”

实现“org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version”

实现“org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version”

但警告仍然存在。构建仍然成功运行,我知道我可以毫无问题地隐藏警告并忽略它,但我真的想知道为什么会发生这种情况以及如何摆脱它。我正在使用 Android Studio 3.0.1。有谁知道这个问题的解决方案吗?

最佳答案

从 Kotlin 1.4 开始对默认添加的标准库的依赖:

You no longer need to declare a dependency on the stdlib library in any Kotlin Gradle project, including a multiplatform one. The dependency is added by default.

The automatically added standard library will be the same version of the Kotlin Gradle plugin, since they have the same versioning.

For platform-specific source sets, the corresponding platform-specific variant of the library is used, while a common standard library is added to the rest. The Kotlin Gradle plugin will select the appropriate JVM standard library depending on the kotlinOptions.jvmTarget compiler option of your Gradle build script.

Link Kotlin Gradle 插件文档。

关于android - 警告 "Kotlin plugin version is not the same as library version"(但它是!),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49956051/

相关文章:

kotlin - 为什么 UInt 没有 toDouble()?

android - RealmObject 的 Kotlin 数据类

kotlin - 如何组织 Kotlin 扩展方法

gradle - 使用Gradle Kotlin DSL在Gradle中进行样板项目配置

android - Kotlin:const val 与 val

android - 在库模块中使用 Kotlin,而不在 app 模块中使用它

java - 为什么以及何时将 @JvmStatic 与伴随对象一起使用?

java - Kotlin 泛型 Array 结果为 "Cannot use T as a r

android - 更新到 Kotlin 1.3.30 会破坏 Dagger 2.21 的构建

parallel-processing - Kotlin 集合的并行操作?