Search code examples
androidandroid-databinding

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 errors.

However, I have been getting a warning in the Gradle sync logs for each module that I think is a false positive:

> Configure project :feature-a
Kotlin plugin is applied to the project :feature-a but we cannot find the KaptTask. Make sure you apply the kotlin-kapt plugin because it is necessary to use kotlin with data binding.

> Configure project :feature-b
Kotlin plugin is applied to the project :feature-b but we cannot find the KaptTask. Make sure you apply the kotlin-kapt plugin because it is necessary to use kotlin with data binding.

> Configure project :feature-c
Kotlin plugin is applied to the project :feature-c but we cannot find the KaptTask. Make sure you apply the kotlin-kapt plugin because it is necessary to use kotlin with data binding.

[... etc. for dozens of modules ...]

I have checked to make sure that the "kotlin-kapt" plugin is properly applied. I'm using the Kotlin Gradle DSL for all modules and am applying the plugin like this:

plugins {
    id("com.android.library")
    id("kotlin-android")
    id("kotlin-android-extensions")
    id("kotlin-kapt")
    id("androidx.navigation.safeargs.kotlin")
}

What is causing this warning, is it actually a problem, and how do I get it to disappear?


Solution

  • 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