Android Databinding build fail after Gradle plugin update with migration to annotationProcessor

怎甘沉沦 提交于 2019-12-03 12:45:35
kristyna

I had exactly the same warning. This line in gradle solved the issue:

kapt "com.android.databinding:compiler:3.0.1"

Hopefully, it will help somebody

Update:
3.0.1 is Android Plugin Version.

When you see innumerable build errors mentioning databinding as in this case, the problem usually lies somewhere else. Databinding just gets stopped in its tracks by unrelated build problems and complains exceedingly loudly. The only way to deal with it is to locate the build errors that are not tied to databinding. Once they are fixed, databinding can do its thing again and be silent. Unfortunately you often have to repeat this approach several times until you have found all non-databinding issues. It's an arduous task for sure, but unfortunately there is nothing else you can do until Google manages to provide a saner build environment.

This is the reason why you are advised to increase the build error limit beyond 100 - you would not see the actual errors causing your problems, because they commonly do not show up early in the list.

I will chance a guess - Dagger 2 is a common source of triggering this problem, which could be related to your annotationProcessor change; so look out for Dagger errors. But your issues could be caused by other things, like other annotation processors as you mentioned - you wouldn't know for sure until you diligently dig through your build errors.

It seems it all comes down to my project using Kotlin. Actually we have it mixed: some classes use plain old Java while others are written in Kotlin. An incomplete migration. :)

I assume that without Kotlin, replacing apt with annotationProcessor would be enough and I wouldn't have ran into this issue at all.

Solution

Annotations need to be processed by both annotationProcessor and kapt, which seems to be Kotlin's own annotation processor.

For each Gradle dependency that uses annotations, you should have both of the following in your app-level build.gradle:

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