8

Since the new Android Studio 3.6 update, my databinding classes show "Cannot resolve symbol"

The code itself is completely fine and it even compiles successfully, but everywhere I'm calling the binding classes, Android Studio gives me the "Cannot resolve symbol" error. This goes through every class or xml I'm using databinding in.

Did anyone of you experience the same? It seems weird, that the update to 3.6 did that. Gradle version used is 3.6.1

Thank you!

Edit: I for now have taken every step I can as a developer, reconfigured everything, tried on different machines etc. I'm not sure if this is a problem of the project I'm working on or a bug of 3.6 that only occurs when some criterias are met, since I'm not the only one, having this exact problem. Below is a screenshot of it to give you an idea how it looks.

Screenshot of the Problem

Final Edit

Seems like upgrading to the Android Studio 4.0 Beta 1 fixed the problem for me now. This seems to be an Android Studio 3.6 related issue. Don't know if using a beta version is a possible solution for you, but for me this solved it completely

Bjonic
  • 192
  • 12
  • have you tried the usual of -> invalidate caches and restarting – a_local_nobody Mar 03 '20 at 10:08
  • yes, i've been through all that, but the invalidate caches thingy didn't work and cleaning and rebuilding my project didn't yield any results either. I also recloned the project since these files are all generated, but that also didn't help. – Bjonic Mar 03 '20 at 10:12
  • if above comment not works, try to delete all *.iml & .idea folder, then do invalidate cache & restart – Priyanka Mar 03 '20 at 10:13
  • Does this answer your question? [Kotlin-android: unresolved reference databinding](https://stackoverflow.com/questions/33165324/kotlin-android-unresolved-reference-databinding) – Antonis Radz Mar 03 '20 at 10:20
  • @Priyankagb Tried this just now and unfortunately didn't resolve the problem. – Bjonic Mar 03 '20 at 10:25
  • deleting build folder may work, delete build folder of each module than run app – Priyanka Mar 03 '20 at 10:28
  • @AntonisRadz Yes, I searched for it. A lot. It isn't the same problem as in the thread you posted, since his code didn't compile when he started using kotlin. As I said, my code just compiles fine, it is Android Studio, which shows me an error within the editor since the 3.6 update. Just to make sure I included the kapt compile databinding line in my build.gradle, synced and rebuilt my project and invalidated caches, but I have still the same issue. – Bjonic Mar 03 '20 at 10:29
  • @Priyankagb Unfortunately, this didn't do anything either :/ – Bjonic Mar 03 '20 at 10:45
  • To give you an idea how this looks to me, heres a screenshot of an onCreateView() https://imgur.com/a/5rwN8bu – Bjonic Mar 03 '20 at 10:45
  • :O don't know what to do now – Priyanka Mar 03 '20 at 10:52
  • @Bjonic Facing same issue, i am using Android studio 4.1.1, cannot resolve symbol on all the binding classes but still project compiles and could run successfully. Any idea how i can solve it?? tried few solution nothing works – Madhu Apr 08 '21 at 12:45

6 Answers6

3

Seems like upgrading to the Android Studio 4.0 Beta 1 fixed the problem for me now. This seems to be an Android Studio 3.6 related issue. Don't know if using a beta version is a possible solution for you, but for me this solved it completely

Bjonic
  • 192
  • 12
2

What works for me is going into a layout xml file, removing/adding/changing text in it, then putting the file back to normal (ctrl-z). Then the "errors" disappear. I'm specifically using Kotlin, so perhaps it's only a Kotlin issue? Does the same thing to me with viewbinding as well (same "fix")

Kobato
  • 726
  • 1
  • 7
  • 15
0

Solved same issue with next steps:

  1. comment all codelines where binding class is used
  2. run Build->Rebuild Project
  3. uncomment all lines from step 1

Looks like sometimes AS can't generate Binding class cause your code links to it but class doesn't exist. Some kind of cyclic dependency

Yamko
  • 535
  • 1
  • 3
  • 13
  • I tried this now for 3 different classes and unfortunately that didn't work for me either ._. Turned out as very unpractical aswell, since this is a huge project with lots of classes and if you comment the binding, you also have to comment everything that depends on it. I also investigated a little further and I can see all the binding classes within the app/build/generated folder – Bjonic Mar 04 '20 at 09:39
  • Had same case when classes were generated but still AS showed error. "Invalidate cache and restart" helped me – Yamko Mar 04 '20 at 12:30
0

I rewrote <layout> tag in all my layouts, and it is helped me.

0

This is really annoying, for it fixes when I clean and rebuild the project

Pianisimo
  • 99
  • 1
  • 6
-1

Just Clean your Project and that's it.

  • 1
    Your answer adds no different solution to the above problem. ***Cleaning the project*** is already present in others answers. Suggesting to either [edit] or delete the answer. – Abhishek Dutt Jul 05 '22 at 03:21