Skip to content Skip to sidebar Skip to footer

Android Data Binding: How To Avoid "cannot Find The Kapttask" Warning

I have a large Android project with multiple library modules. They all use Kotlin, and many have data binding enabled. The project and all modules build and run just fine with no e

Solution 1:

This problem can also occur if you have Android Gradle plugin dependency declared in your buildSrc/build.gradle[.kts]: https://issuetracker.google.com/issues/123491449

A work-around for this is to declare ALL of your plugin dependencies in buildSrc/build.gradle[.kts] instead of your root project's build.gradle[.kts] file

Solution 2:

The real reason behind this issue is that kotlin gradle plugin wasn't applied

You can find the code that prints the error in TaskManager

try {
   //noinspection unchecked
   kaptTaskClass = (Class<? extendsTask>) Class.forName("org.jetbrains.kotlin.gradle.internal.KaptTask");
} catch (ClassNotFoundException e) {
            logger.error(
                    "Kotlin plugin is applied to the project "
                            + project.getPath()
                            + " but we cannot find the KaptTask. Make sure you apply the"
                            + " kotlin-kapt plugin because it is necessary to use kotlin"
                            + " with data binding.");
        }

As you can see, it can't resolve org.jetbrains.kotlin.gradle.internal.KaptTask

In my case, this happened after migrating to convention plugins. I forgot to add implementation kotlinPlugin to buildSrc/build.gradle

repositories { ... }

dependencies {
    implementation gradlePlugins.android
    implementation gradlePlugins.kotlin
}

Once I added that, the issue was solved

The weird thing is, I ignored this warning for weeks because everything built fine, until suddenly databinding stopped working. My guess is that there was some kind of race condition where we did apply kotlin plugin at some other point of our build, and that it stopped working after some change.

Solution 3:

This error is coming from the databinding annotation processor. To disable it you should only apply the kotlin-kapt plugin once. In any module other than the main one do this:

plugins {
    ...
    id("kotlin-kapt") apply false
    ...
}

Solution 4:

Kotlin plugin is applied to the project :business_module:module_web but we cannot find the KaptTask. Make sure you apply the kotlin-kapt plugin because it is necessary to use kotlin with data binding. Apply plugin in app's build.gradle:

apply plugin: 'kotlin-kapt'

Solution 5:

if you project have buildSrc, you can delete build.gradle ->

implementation gradleApi()
implementation localGroovy()

replease remote url 

Post a Comment for "Android Data Binding: How To Avoid "cannot Find The Kapttask" Warning"