Kotlin编译“错误:Android Gradle插件仅支持1.3.0或更高版本的Kotlin Gradle插件。” 但在build.gradle中没有kotlin_version?

Kur*_*eek 9 android gradle kotlin

我尝试克隆并构建此项目https://github.com/mitrejcevski/ui-testing,但是在Android Studio中打开它后,出现以下构建错误:

ERROR: The Android Gradle plugin supports only Kotlin Gradle plugin version 1.3.0 and higher.
The following dependencies do not satisfy the required version:
root project 'ui-testing' -> org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.21
Affected Modules: app
Run Code Online (Sandbox Code Playgroud)

但是,当我单击“ app”超链接时,我被带到模块级build.gradle文件,该文件显示为

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

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "nl.jovmit"
        minSdkVersion 19
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    productFlavors {
        mock {
            flavorDimensions "default"
        }
        prod {
            flavorDimensions "default"
        }
    }

    android.variantFilter { variant ->
        if (variant.buildType.name == 'release' && variant.getFlavors().get(0).name == 'mock') {
            variant.setIgnore(true)
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
    implementation "com.android.support:appcompat-v7:$support_version"
    implementation "com.android.support:design:$support_version"
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    implementation 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.21'

    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'
}
Run Code Online (Sandbox Code Playgroud)

与公认的错误答案不同:Android Gradle插件仅支持1.3.0或更高版本的Kotlin Gradle插件,我ext.kotlin_version在Gradle文件中看不到任何地方。

我确实看到了此警告,但kotlin-stdlib-jre7已弃用:

在此处输入图片说明

但是,我尝试更改此设置,但仍然收到相同的错误。我也尝试添加行

implementation 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.21'
Run Code Online (Sandbox Code Playgroud)

dependencies(如上面的屏幕快照中所示),但这也不能避免错误。

任何想法如何解决这个问题?我怀疑过时的Kotlin版本是此处依赖项之一的“子依赖项”,但无法确定是哪个。

Deb*_*jan 12

定义你的 ext.kotlin_version

您的项目级别build.gradle应该如下所示。

buildscript {
    ext.kotlin_version = '1.2.51'
    ext.android_plugin_version = '3.2.1'
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:$android_plugin_version"
        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
    }
}
Run Code Online (Sandbox Code Playgroud)


Lon*_*gLv 8

更改

org.jetbrains.kotlin:kotlin-stdlib-jre7:$ kotlin_version

代替

org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version
Run Code Online (Sandbox Code Playgroud)


Tin*_*she 6

  1. 转到工具 > SDK 管理器 > Kotlin
  2. 安装新的插件版本
  3. 确保您的项目级别build.gradle如下所示
buildscript {
    ext.kotlin_version = '1.3.10' //put the version you just updated to
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.4.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}
Run Code Online (Sandbox Code Playgroud)


小智 5

在react-native中你需要使用ext.kotlinVersionand NOT ext.kotlin_version

因为所有依赖项都会出于这个原因尝试获取,rootProject.ext.kotlinVersion如果找不到,那么它们就会回退到默认值。因此,您会收到使用不同 Kotlin 版本的错误。