106

Gradle DSL method not found: 'kapt()' Possible causes: The project 'jetpacklearn' may be using a version of the Android Gradle plug-in that does not contain the method (e.g. 'testCompile' was added in 1.1.0). Upgrade plugin to version 3.4.0 and sync project

The project 'jetpacklearn' may be using a version of Gradle that does not contain the method. Open Gradle wrapper file

My gradleVersion is '3.4.0', but can not deal with it , ask me the same question

    classpath "com.android.tools.build:gradle:$gradleVersion"
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
    classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$navigationVersion"
Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
cheng zhang
  • 1,081
  • 2
  • 7
  • 3
  • 3
    Why is this downvoted? It's a valid question, and you run into this error message by following the official Android documentation. What's more, the built-in suggestion in the error message is confusing and wrong (talking about upgrading to Gradle 1.0 when we're on version 3.x). – Andrew Koster Jun 01 '19 at 20:59

9 Answers9

227

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

apply plugin: 'kotlin-kapt'
Ignacio Tomas Crespo
  • 3,401
  • 1
  • 20
  • 13
89

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'
Kourosh
  • 2,239
  • 13
  • 18
  • 1
    Thank you so much. This was my issue. Even the Android docs for getting started with Hilt did not mention this. https://developer.android.com/training/dependency-injection/hilt-android – Cb32019 Aug 14 '20 at 16:16
34

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

apply plugin: 'kotlin-kapt'

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

Sana Ebadi
  • 6,656
  • 2
  • 44
  • 44
  • NOTE.... mentioned here is very powerful. I never thought the order of the plugins matters. Thanks a lot. – skafle Aug 12 '23 at 12:22
24

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

apply plugin: 'kotlin-kapt'

tonny
  • 419
  • 4
  • 4
16

Your build.Gradle file should have these at the top

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
C Williams
  • 850
  • 12
  • 19
5

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

apply plugin: 'kotlin-kapt'
tech.mohit.garg
  • 631
  • 8
  • 18
4

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')
}
Luke Needham
  • 3,373
  • 1
  • 24
  • 41
2

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'
0

This is because you are missing something in gradle. if your using kotlin DSL add this

in project-level build.gradle.kts

plugins {
   id("com.google.devtools.ksp") version ("1.8.21-1.0.11") apply false
}

in app_level build.gradle.kts file

plugins {
   id("com.google.devtools.ksp")
}

and add those dependencies

 implementation("androidx.room:room-common:2.5.2")
 implementation("androidx.room:room-ktx:2.5.2")
 ksp("androidx.room:room-compiler:2.5.2")
Adarsh Dhakad
  • 347
  • 1
  • 3
  • 10