如何在库模块中使用 Android 视图绑定?
我想我知道这个问题的答案,但是......
我在库模块中启用了视图绑定。美好的。然后,我获取该 .AAR 并在另一个应用程序中使用它,但我未在该应用程序中启用了视图绑定。当我运行该应用程序并从库中启动一个活动时,我得到
java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/viewbinding/ViewBinding;
如果我然后在应用程序中启用视图绑定,则一切正常。看来我应该能够在库中使用视图绑定,而不必在应用程序中启用它。
也许必要的课程被 Proguarded 拿走了?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(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
instead of enabling View Binding, which solved my problem.
检查此 androidx/viewbinding/ViewBinding 已在 apk 中
check this androidx/viewbinding/ViewBinding has in apk