未找到 Gradle DSL 方法: ‘ kapt()’

未找到 Gradle DSL 方法: ‘ kapt ()’ 可能的原因: “ jetpacklearn”项目可能使用了不包含该方法的 Android Gradle 插件版本(例如,在1.1.0中添加了“ testCompile”)。 将插件升级到3.4.0版并同步项目

“ jetpacklearn”项目可能使用的 Gradle 版本不包含这种方法。 打开 Gradle 包装文件

我的 gradleVersion 是“3.4.0”,但不能处理它,问我同样的问题

    classpath "com.android.tools.build:gradle:$gradleVersion"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$navigationVersion"
28731 次浏览

Check if you have this in top of your app build.gradle?

apply plugin: 'kotlin-kapt'

Add this in your build.gradle then sync the gradle again.

apply plugin: 'kotlin-kapt'

add this line

apply plugin: 'kotlin-kapt'

if you used kapt in android library you must add kotlin-android plugin in your project

apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'

just add this line in your app-level of build.grale :

apply plugin: 'kotlin-kapt'

NOTE: under apply plugin: 'com.android.application'

The answer https://stackoverflow.com/a/56101024/6007104 is absolutely correct.

But, for people using the gradle plugins block, it looks like this:

plugins {
id('kotlin-kapt')
}

Your build.Gradle file should have these at the top

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'

apply the below plugin in your app-level build.gradle.

apply plugin: 'kotlin-kapt'

This is because you are missing apply 'kotlin-kapt' in app level gradle. There is two ways to add this plugin.

if your project having plugin block. please add like below.

plugins {
...
...
id 'kotlin-kapt'
}

or you can add by using apply key word.

apply plugin: 'kotlin-kapt'