如何在库模块中使用 Android 视图绑定?

发布于 2025-01-12 17:22:22 字数 340 浏览 4 评论 0原文

我想我知道这个问题的答案,但是......

我在库模块中启用了视图绑定。美好的。然后,我获取该 .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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

壹場煙雨 2025-01-19 17:22:22

我认为当我启用视图绑定时,它可能添加了一个我没有看到的库。我发现我可以添加

implementation 'androidx.databinding:viewbinding:7.1.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.

心是晴朗的。 2025-01-19 17:22:22

检查此 androidx/viewbinding/ViewBinding 已在 apk 中

check this androidx/viewbinding/ViewBinding has in apk

check this androidx/viewbinding/ViewBinding has in apk

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文