In order to get data binding to work across multiple modules - in my case - I had to make sure that each Android Studio module (library, phone/tablet, etc) has data binding enabled in its corresponding build.gradle
(not just for the library .gradle file, as that was not enough),
like so:
android {
...
defaultConfig {
...
}
buildTypes {
...
}
// Looks like this needs to be set in the app module that uses the lib
// The lib needs it for the layout binding code there
dataBinding {
enabled = true
}
}
The project structure where solution is applied :
There is a library module, and multiple "app modules" (aka, Android Studio module for Phone or Tablet that can be run) that use Activities/layouts from that library in the same project
The library project has .xml under /res/layout that relies on data binding, like so:
<TextView
android:id="@+id/display_name_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="@={user.displayName}"
android:textSize="20sp"/>
This one was a bit tricky to resolve. Especially in my case where I have multiple modules. After I applied this solution for the main module I was working with, I still continued getting build errors. Finally I noticed in all the error output that there was 1 other module - which I hadn't been working with - that also had the library as dependency , but was missing the data binding enable in build.gradle
. When finally that was identified and addressed, the builds are working fine. I'm glad to have found this as it makes things a lot nicer when you can reuse layouts with data binding across multiple modules