简体   繁体   English

带有数据绑定的 Android 项目中的 ViewBinding 错误

[英]ViewBinding error in Android project with Data Binding

I have a project working with Data Binding:我有一个使用数据绑定的项目:

buildFeatures  {
        dataBinding true
}

After I changed it to:在我将其更改为:

buildFeatures  {
    dataBinding true
    viewBinding true
}

The gradle sync is fine, but I get an error in Data Binding classes when try to run the project: gradle 同步很好,但是在尝试运行项目时出现数据绑定类错误:

:app:kaptHomologDebugKotlin
app/build/generated/source/kapt/homologDebug/br/com/test/DataBinderMapperImpl.java
cannot find symbol class ConfirmacaoFragmentBindingImpl
java.lang.reflect.InvocationTargetException (no error message)
Cannot find a setter for  that accepts parameter type 'int'

error image错误图像

I've already tried rebuild and invalidate cache我已经尝试过重建并使缓存无效

The documentation says "Because of these considerations, it is best in some cases to use both view binding and data binding in a project" . 文档“由于这些考虑,在某些情况下最好在项目中同时使用视图绑定和数据绑定”

So it's possible to have both in a project所以可以在一个项目中同时拥有两者

I had the same problem when I tried to use view binding on an existing project that already has data binding enabled, in my case, the problem was caused by some includes (these includes were being used inside layout that was using data binding) and some of those layouts which were using as an include didn't have the layout tag, the layout tag is required to generate the data binding implementation classes, I don't know the reason exactly for this conflict, but when I enabled the view binding, the error began to happen, so by putting the layout tag in all layouts that were being used with data binding or as an include inside a layout with data binding, I could solve my problem.当我尝试在已经启用数据绑定的现有项目上使用视图绑定时,我遇到了同样的问题,在我的情况下,问题是由一些包含(这些包含在使用数据绑定的布局内部使用)和一些引起的那些用作包含的布局中没有布局标签,需要布局标签来生成数据绑定实现类,我不知道这个冲突的确切原因,但是当我启用视图绑定时,错误开始发生,因此通过将布局标记放置在与数据绑定一起使用的所有布局中或作为包含在具有数据绑定的布局中,我可以解决我的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM