当前位置: 首页 > 知识库问答 >
问题:

错误:Android Gradle插件只支持Kotlin Gradle插件1.3.0及更高版本。但是没有构建kotlin_version。gradle?

裴翰学
2023-03-14

我尝试克隆并构建这个项目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'
}

与公认的错误答案不同:Android Gradle插件只支持Kotlin Gradle插件1.3.0及更高版本,我在Gradle文件中没有看到任何ext.kotlin_version

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

dependencies(如上面的截图所示),但这也不能阻止错误。

你知道怎么解决这个问题吗?我怀疑过时的Kotlin版本是这里依赖项之一的“子依赖项”,但还不能确定是哪一个。

共有1个答案

司寇研
2023-03-14

定义ext.kotlin_version

您的项目级别构建。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
    }
}
 类似资料: