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

时间:2019-02-25 01:56:48

标签: 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

但是,当我单击“ 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'
}

与公认的ERROR: The Android Gradle plugin supports only Kotlin Gradle plugin version 1.3.0 and higher答案不同,我在Gradle文件的任何位置都看不到任何ext.kotlin_version

不过,我确实看到了以下警告:kotlin-stdlib-jre7已过时:

enter image description here

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

implementation 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.21'

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

有人知道如何解决此问题吗?我怀疑过时的Kotlin版本是此处依赖项之一的“子依赖项”,但无法找出哪个依赖项。

7 个答案:

答案 0 :(得分:5)

定义您的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
    }
}

答案 1 :(得分:2)

更改

  

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

代替

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

答案 2 :(得分:0)

我也遇到了这个问题,并通过以下操作解决了该问题:

  • 在项目级别的build.gradle中,我有ext.kotlin_version ='1.3.10'

buildscript {
    ext.kotlin_version = '1.3.10'
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.4.0'
        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
    }
}

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

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

ext {
    roomVersion = '1.0.0'
    archLifecycleVersion = '1.1.0'
}
  • 然后在应用程序级别build.gradle中,我更新了依赖项以使其具有以下功能: implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"

我建造了,一切又恢复正常了。

答案 3 :(得分:0)

  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"
    }
}

答案 4 :(得分:0)

只需转到您的项目级别的构建文件 并更改以下内容

 buildscript {
  ext {
kotlin_version = '1.3.10'
support_version = '28.0.0-rc02'
room_version = '1.1.1'
arch_comp_version = '1.1.1'
  }
 }

只需将kotlin版本更新到1.3.10或更高版本即可修复它。

答案 5 :(得分:0)

转到外部库/ Flutter插件/ ui_testing / android / build.gradle,并将ext.kotlin_version更改为LATEST_VERSION。

答案 6 :(得分:0)

将您的 kotlin 依赖项更改为:

{{1}}