Does view binding work between modules?
How to reproduce: Create 2 modules >>> create layout1 in module1 and create layout2 in module2 >>> Create Fragment1 in module1 with view which will be including layout1, layout2 >>> try to get binding >>> layout1 will work becouse it is in the same module as Fragment1, but layout2 will not work becouse of wrong binding generation
My example:
Authentication module has dependency to common module.
base_button.xml is in common module.
login_input_component.xml is in Authentication module so there is no problem.
But this error occures on loginButton binding.
It tries to find BaseButtonBinding in authentication module even if base_button.xml is in another module.
All modules has:
buildFeatures {
dataBinding = true
viewBinding = true
}
If I am correct you have this kind of structure
project
| -- app
| -- module1 [ contains layout_one.xml and layout_fragment.xml]
| -- module2 [ contains layout_two.xml]
layout_fragment.xml
will include both layout_one.xml
and layout_two.xml
Now in order to make this work, all you need to do is go to module1 build.gradle
file and add this dependency
implementation project(":module2")
Note your app will be aware of module1 and module2 files but module1 and module2 files will not be aware of both of there existence. So by specifying this dependency we make module1 to depend on module2
and also make sure in each module viewBinding is enabled
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With