简体   繁体   中英

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:

: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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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