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

时间:2019-02-02 01:21:36

标签: android gradle kotlin

我已经完全复制了kotlin gradle docs say来实现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
}

有什么主意吗?

1 个答案:

答案 0 :(得分:0)

您正在使用的不是Kotlin DSL(您正在选择“ 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项目来找到一个不错的示例。