【发布时间】:2019-07-18 09:40:09
【问题描述】:
我尝试克隆和构建这个项目,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
但是,当我单击“应用程序”超链接时,我会转到模块级 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 已被弃用:
但是,我尝试更改此设置,但仍然出现相同的错误。我也试过添加这条线
implementation 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.21'
到dependencies(如上面的屏幕截图所示),但这也不能阻止错误。
知道如何解决这个问题吗?我怀疑过时的 Kotlin 版本是此处依赖项之一的“子依赖项”,但无法确定是哪一个。
【问题讨论】:
-
Kotlin 版本在项目的 build.gradle,而不是应用的 build.gradle。
-
检查项目的 build.gradle。如果您只是通过单击 Android Studio 的提示来更新 kotlin 版本,您最终可能会得到多个
ext.kotlin_version='...'。删除除最新的以外的所有内容。 -
我做了一些补充。 1.依赖应该在buildscript config body中。因为是 gradle 插件依赖支持 kotlin compile(就像名字 kotlin-gradle-plugin,更准确的说是 apply plugin: 'kotlin-android'),不是你的 app 依赖。