Databinding annotation processor kapt warning

落爺英雄遲暮 提交于 2019-12-18 12:17:26

问题


In my app module's build.gradle, I have added

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

but I'm still receiving the compiler warning for

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

Everything functions, I just hate having warnings hanging around.

Any help is much appreciated!


回答1:


I had same warnings until I upgraded to the latest Android Gradle build plugin and Kotlin. Now they are gone. Here is the configuration I use.

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
}

Hope it helps.




回答2:


Add following in you app build.gradle

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

This will do the trick.

$android_plugin_version is version of com.android.tools.build:gradle in application build.gradle

Also, add this to your module build.gradle

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

You are missing apply plugin: 'kotlin-kapt' i think.



来源:https://stackoverflow.com/questions/50137564/databinding-annotation-processor-kapt-warning

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!