28

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!

cren90
  • 1,367
  • 2
  • 17
  • 30
  • 1
    do you have other dependencies that use annotationProcessor? – peshkira May 02 '18 at 14:55
  • In my build.gradle, all other dependencies are "implementation", "testImplementation", or "androidTestImplementation". I don't know if the 3rd party dependencies I have are using annotation processing. – cren90 May 02 '18 at 15:57
  • Same problem here. Plus I get this error: e: java.util.ServiceConfigurationError: javax.annotation.processing.Processor: android.databinding.annotationprocessor.ProcessDataBinding Unable to get public no-arg constructor – cesards May 06 '18 at 01:57
  • `kapt` is for kotlin and `annotationProcessor` for java code – Ryan Amaral May 18 '18 at 18:34
  • @RyanAmaral, I am aware of that, and am using kapt in my build.gradle (above) but still get the warning – cren90 May 18 '18 at 20:27
  • [Solved Databinding annotation processor kapt warning .](https://stackoverflow.com/a/60275454/5788247) – Shomu Feb 18 '20 at 07:15

2 Answers2

17

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.

sergej shafarenka
  • 20,071
  • 7
  • 67
  • 86
1

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.

Roaim
  • 2,298
  • 2
  • 11
  • 23
Randheer
  • 984
  • 6
  • 24