[英]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.
然后我将那个.AAR 用于另一个我没有启用视图绑定的应用程序中。 When I run that app and start an Activity from the library, I get
当我运行该应用程序并从库中启动一个 Activity 时,我得到
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?也许必要的 class 会被 Proguarded 带走吗?
I figured that when I enabled View Binding, it was probably adding a library that I wasn't seeing.我想当我启用 View Binding 时,它可能会添加一个我没有看到的库。 I discovered I could add
我发现我可以添加
implementation 'androidx.databinding:viewbinding:7.1.2'
instead of enabling View Binding, which solved my problem.而不是启用视图绑定,这解决了我的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.