数据绑定注释处理器 kapt 警告

Databinding annotation processor kapt warning

在我的应用程序模块的 build.gradle 中,我添加了

dependencies {
kapt('com.android.databinding:compiler:3.1.2')
...
}

但我仍然收到

的编译器警告
app: 'annotationProcessor' dependencies won't be recognized as kapt annotation processors. Please change the configuration name to 'kapt' for these artifacts: 'com.android.databinding:compiler:3.1.2'.

一切正常,我只是讨厌到处都是警告。

非常感谢任何帮助!

关注你app build.gradle

kapt "com.android.databinding:compiler:$android_plugin_version"
apply plugin: 'kotlin-kapt' // This one at top where plugin belong to

这样就可以了。

$android_plugin_versionapplication build.gradle

com.android.tools.build:gradle 的版本

此外,将此添加到您的模块中 build.gradle

android {
    /// Existing Code
    kapt {
        generateStubs = true
    }
}

我想你不见了apply plugin: 'kotlin-kapt'

在升级到最新的 Android Gradle 构建插件和 Kotlin 之前,我收到了相同的警告。现在他们走了。这是我使用的配置。

project.gradle

buildscript {
    dependencies {
        classpath "com.android.tools.build:gradle:3.1.3"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.51"
    }
}

module.gradle

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

android {
    ...
    dataBinding {
        enabled = true
    }
}

dependencies {
    // no kapt declaration for databinding here
}

希望对您有所帮助。