'How do I use Android View Binding in a library module?
I think I know the answer to this, but...
I enabled View Binding in a library module. Fine. I then take that .AAR and use it in another app, where I've not enabled View Binding. When I run that app and start an Activity from the library, I get
java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/viewbinding/ViewBinding;
If I then enable view binding in the app, everything works fine. It seems like I should be able to use view binding in a library without having to also enable it in the app.
Is the necessary class getting Proguarded away, perhaps?
Solution 1:[1]
Solution 2:[2]
I figured that when I enabled View Binding, it was probably adding a library that I wasn't seeing. I discovered I could add
implementation 'androidx.databinding:viewbinding:7.1.2'
instead of enabling View Binding, which solved my problem.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | shuabing |
| Solution 2 | Fred Ross-Perry |

