12
  • To support Instant Run in my version of Android Studio, I needed to upgrade my Gradle plugin from version 2.2.3 to 2.3.3
  • I'm aware I'm supposed to migrate to annoationProcessor and I believe I've followed that guide correctly
  • after doing so, the Android DataBinding code generation fails

The migration guide linked earlier states that all I need is to

  • Make sure you are on the Android Gradle 2.2 plugin or newer
  • Remove the android-apt plugin from your build scripts
  • Change all apt, androidTestApt and testApt dependencies to their new format

This should be all that's needed to successfully build the project. Yet it doesn't build.

Build output

Gradle build finished with 101 error(s) and 23 warning(s) in 12s 481ms

All of the errors follow the same pattern:

  • C:\Users...\FooAdapter.java
    • error: package com.example.app.databinding does not exist
    • error: cannot find symbol class ItemFooBinding

An interesting message can be found in the build console:

Warning:The following options were not recognized by any processor: '[android.databinding.minApi, android.databinding.enableDebugLogs, android.databinding.sdkDir, android.databinding.bindingBuildFolder, android.databinding.enableForTests, android.databinding.modulePackage, android.databinding.generationalFileOutDir, android.databinding.xmlOutDir, android.databinding.artifactType, android.databinding.printEncodedErrors, android.databinding.isTestVariant]'

I would like to point out that...

  • I presume I don't have an error in some XML file, binding expression or a naming issue. The same set of sources and XML build when I switch back to the Git branch with the old gradle plugin version (and all of the other source files up-to-date)
  • I did increase the limit of output build errors as discussed here, although this doesn't seem to be relevant right now, since as you can see, I currently have "only" 101 errors. :)

Additional info

The following diffs show how I've modified my gradle files:

  1. build.gradle DiffChecker link
  2. app/build.gradle DiffChecker link

Also, as a quick overview, here is the list of some of the "more interesting" plugins & libraries used by the project:

  • Kotlin
  • Android DataBinding
  • Realm
  • Retrofit
  • Dagger
  • ButterKnife (I know...)
  • Multidex Support Library

Does anyone have a clue what could be the issue? Any help or idea will be greatly apprecitated!

oli.G
  • 1,300
  • 2
  • 18
  • 24
  • 1
    You may try to use `gradle v 3.3` i.e. setting distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip in `gradle-wrapper.properties` to solve this problem. – Akram Jul 18 '17 at 12:35
  • I failed to mention it but I am using that URL.. thanks for the tip though :) – oli.G Jul 18 '17 at 12:54
  • The project uses both Java and Kotlin files and it seems that the issue is somehow related to Kotlin and its own annotations processing. I'm still investigating this, but if this comment gave anyone an idea, please do post! – oli.G Jul 18 '17 at 12:55
  • 1
    I have the same issue. – Nominalista Jul 18 '17 at 20:23
  • I may have a solution already, just need to summarize it, I'll post it later today :) – oli.G Jul 19 '17 at 11:01

3 Answers3

16

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.

Dr.jacky
  • 3,341
  • 6
  • 53
  • 91
kristyna
  • 1,360
  • 2
  • 24
  • 41
2

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.

Uli
  • 2,828
  • 20
  • 23
0

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
oli.G
  • 1,300
  • 2
  • 18
  • 24
  • 11
    It's the wrong answer. You shouldn't use kapt together with annotationProcessor. Kapt can process both Java and Kotlin files and even warn you, that you shouldn't use annotationProcessor, so if you have both, you have a chance to get some additional problems with AP. If you need AP for Kotlin files use only Kapt – gildor Sep 28 '17 at 01:45
  • 1
    After spending several hours on a similar issue, this solution worked for me. – M-Wajeeh Jan 11 '18 at 01:46