找不到参数的方法 kotlin() [gradle-plugin, 1.3.20]



我已经完全复制了 kotlin gradle 文档所说的来实现 kotlin gradle 插件,但它返回以下错误:

Could not find method kotlin() for arguments [gradle-plugin, 1.3.20] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

我的毕业生

buildscript {
    ext.kotlin_version = '1.3.0'
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.3.0'
        classpath(kotlin("gradle-plugin", version = "1.3.20"))
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
//    ext {
//        navigationVersion = '28.0.0'
//    }
    plugins {
        kotlin("<...>")
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}
task clean(type: Delete) {
    delete rootProject.buildDir
}

知道吗?

build.gradle可以用Groovy或Kotlin编写。您正在 Groovy(不是 Kotlin(中键入build.gradle,但您已经复制了 Kotlin 代码。您应该选择文档中的 Groovy 选项卡:

buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:3.3.0"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.20"
    }
}

在这里: https://kotlinlang.org/docs/reference/using-gradle.html#targeting-android

你也可以通过创建一个空的 Android 和 Kotlin 项目来找到一个体面的例子。

相关内容

最新更新