Ad

Gradle Cannot Resolve Generated Classes

I was using Data Binding in my android project and it was working flawlessly until yesterday. I don't know what had happened but now cannot compile my project any more:

error: cannot find symbol class BR

The interesting part is, the Data Binding related classes are generated as expected, I can navigate into BR and view all variables there.

The generated sources are at build/generated/source/apt/debug location. Android Studio also displays generatedJava folder, including the BR class, as follows:

SS from Android Studio

The iml file contains an entry as follows:

  <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
    ...
    <content url="file://$MODULE_DIR$">
      ...
      <sourceFolder url="file://$MODULE_DIR$/build/generated/source/apt/debug" isTestSource="false" generated="true" />
      ...
    </content>
  </component>

Everything seems to be quite normal. I restarted AS, invalidated cache, deleted .gradle folder in project, cleared .gradle/caches in home folder, but no luck!

When I Clean Project, the editor shows data binding related classes (including BR) in red, which is as expected. After I Rebuild Project, it gives me this compilation error but these classes are now resolved and I can navigate into them with Cmd + click. After they have been resolved, I try rebuild, make etc. but it always gives me the same compilation error.

I have spent hours on this silly problem, any kind of help is highly appreciated.

PS: The problem seems very similar with this one, but it's very old (i.e. gradle and the plugins are not up to date) and also in comments it is stated that data binding classes are OK.

Ad

Answer

The build window was showing a single error, the one that I have included in question. From terminal, I tried ./gradlew :app:build and it gave me another error, as follows:

Not sure how to handle insert method's return type.

I had added a method to a Dao of Room but the return type was not suitable. That was a mistake. After I fixed that, the other error has gone.

Ad
source: stackoverflow.com
Ad