我有一个包含多个库模块的大型 Android 项目。它们都使用 Kotlin,并且许多都启用了数据绑定(bind)。该项目和所有模块构建和运行都很好,没有错误。
但是,对于我认为是误报的每个模块,我在 Gradle 同步日志中收到警告:
> 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 ...]
我已检查以确保正确应用了“kotlin-kapt”插件。我正在为所有模块使用 Kotlin Gradle DSL,并像这样应用插件:
plugins {
id("com.android.library")
id("kotlin-android")
id("kotlin-android-extensions")
id("kotlin-kapt")
id("androidx.navigation.safeargs.kotlin")
}
是什么导致了这个警告,它真的是一个问题吗?我该如何让它消失?
最佳答案
如果您在 buildSrc/build.gradle[.kts]
中声明了 Android Gradle 插件依赖项,也会出现此问题:https://issuetracker.google.com/issues/123491449
解决此问题的方法是在 buildSrc/build.gradle[.kts]
中声明 ALL 插件依赖项,而不是在根项目的 build 中声明.gradle[.kts]
文件
关于安卓数据绑定(bind) : How to avoid "cannot find the KaptTask" warning,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61808379/