【问题标题】:Kotlin compile "ERROR: The Android Gradle plugin supports only Kotlin Gradle plugin version 1.3.0 and higher." but no kotlin_version in build.gradle?Kotlin 编译“错误:Android Gradle 插件仅支持 Kotlin Gradle 插件版本 1.3.0 及更高版本。”但 build.gradle 中没有 kotlin_version?
【发布时间】: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 依赖。

标签: android gradle kotlin


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    改变

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

    而不是

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

    【讨论】:

    • 这是解决方案的一部分,查看@SavedBeau解决方案
    【解决方案3】:

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

    • 在项目级 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"

    我构建了,一切都恢复正常了。

    【讨论】:

      【解决方案4】:
      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"
          }
      }
      

      【讨论】:

        【解决方案5】:

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

         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 或更高版本。这将解决它。

        【讨论】:

          【解决方案6】:

          “您的项目需要更新版本的 Kotlin Gradle 插件”的 2022 解决方案

          要使用 Gradle 构建 Kotlin 项目,您应该将 Kotlin Gradle 插件应用到您的项目并配置依赖项。 在你的根项目中,然后是 Android/build.gradle

          buildscript {
              ext.kotlin_version = '1.5.31'
              repositories {
                  google()
                  mavenCentral()
              }
          
              dependencies {
                  classpath 'com.android.tools.build:gradle:4.2.2'
                  classpath 'com.google.gms:google-services:4.3.10'
                  classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.31'
              }
          }
          //$kotlin_version removed it to 1.5.31
          allprojects {
              repositories {
                  google()
                  mavenCentral()
              }
          }
          
          rootProject.buildDir = '../build'
          subprojects {
              project.buildDir = "${rootProject.buildDir}/${project.name}"
              project.evaluationDependsOn(':app')
          }
          
          task clean(type: Delete) {
              delete rootProject.buildDir
          }
          

          【讨论】:

            【解决方案7】:

            转到 External Libraries / Flutter Plugins / ui_testing / android / build.gradle 并将 ext.kotlin_version 更改为 LATEST_VERSION。

            【讨论】:

              【解决方案8】:

              将您的 kotlin 依赖项更改为:

              implementation "org.jetbrains.kotlin:kotlin-stdlib:1.4.21"
              

              【讨论】:

                【解决方案9】:

                更新您的项目级别 build.gradle ext.kotlin_version = 'your_current_version' 到 ext.kotlin_version = '1.6.10'

                您可以访问最新版本 => https://kotlinlang.org/docs/gradle.html#targeting-the-jvm

                【讨论】:

                  【解决方案10】:

                  确保您已将 ext.kotlin_version = '1.6.0'classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 添加到 Project/build.gradle 并在 app/build.gradle 中启用 multiDexEnabled true

                  defaultConfig {
                      
                      multiDexEnabled true
                  }
                  
                     buildscript {
                          ext.kotlin_version = '1.6.0'
                      
                          repositories {
                              google()
                              jcenter()
                          }
                      
                          dependencies {
                              classpath 'com.android.tools.build:gradle:4.1.0'
                              classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
                      
                          }
                      }
                      
                      allprojects {
                          repositories {
                              google()
                              jcenter()
                          }
                      }
                      rootProject.buildDir = '../build'
                      subprojects {
                          project.buildDir = "${rootProject.buildDir}/${project.name}"
                      }
                      subprojects {
                          project.evaluationDependsOn(':app')
                      }
                      
                      task clean(type: Delete) {
                          delete rootProject.buildDir
                      }
                  
                  

                  【讨论】:

                    猜你喜欢
                    • 2019-07-03
                    • 2019-07-08
                    • 2023-04-11
                    • 2020-06-11
                    • 2023-02-18
                    • 2019-10-24
                    • 1970-01-01
                    • 2022-10-21
                    相关资源
                    最近更新 更多