【问题标题】:ViewBinding error in Android project with Data Binding使用数据绑定的 Android 项目中的 ViewBinding 错误
【发布时间】:2021-03-05 14:36:39
【问题描述】:

我有一个使用数据绑定的项目:

buildFeatures  {
        dataBinding true
}

我改成之后:

buildFeatures  {
    dataBinding true
    viewBinding true
}

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

我已经尝试过重建和无效缓存

documentation“由于这些考虑,在某些情况下最好在项目中同时使用视图绑定和数据绑定”

所以可以在一个项目中同时拥有两者

【问题讨论】:

    标签: android data-binding android-viewbinding


    【解决方案1】:

    当我尝试在已经启用数据绑定的现有项目上使用视图绑定时,我遇到了同样的问题,在我的情况下,问题是由某些包含引起的(这些包含在使用数据绑定的布局内部使用) 并且其中一些用作包含的布局没有布局标记,布局标记是生成数据绑定实现类所必需的,我不知道这种冲突的确切原因,但是当我启用视图绑定,错误开始发生,因此通过将布局标记放在所有与数据绑定一起使用的布局中或作为包含在具有数据绑定的布局中,我可以解决我的问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-06
      • 1970-01-01
      • 2018-02-07
      • 2017-02-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多