I'm trying to keep my application clean by breaking functionality into multiple modules.
:App
:Features:Foo
:Features:Bar
:Ux
I've defined my application's theme in themes.xml in the :Ux module, and then it's used throughout the application.
<style name="Theme.MyApp" parent="Theme.MaterialComponents.Light">
...
</style>
Some of my features have custom attributes I want to add to the theme and use throughout just that feature, however. So I've added an attrs.xml and themes.xml to each of :Features:Foo and :Features:Bar.
<style name="Theme.MyApp.Foo" parent="Theme.MaterialComponents.Light">
<item name="customFooViewColor">@android:color/holo_orange_dark</item>
</style>
and
<style name="Theme.MyApp.Bar" parent="Theme.MaterialComponents.Light">
<item name="customBarViewColor">@android:color/holo_green_light</item>
</style>
But now I'd like to add a new feature in :Features:Baz that can host fragments from both :Features:Foo and :Features:Bar, so its theme needs to include the custom attributes defined in :Feature:Foo's attrs.xml and :Feature:Bar's attrs.xml, and the same values of those attributes defined in :Feature:Foo's themes.xml and :Feature:Bar's themes.xml.
One solution is to move those custom attributes and their values into the :Ux module, but that pollutes the entire app with feature-specific properties that only are only required in a couple modules.
As @ritesh4302 points out, I can access the attrs.xml files in :Feature:Foo and :Feature:Bar from :Feature:Baz by adding dependencies on those modules, so another solution is to duplicate all the fields in each of :Features:Foo and :Features:Bar into :Features:Baz.
In :Features:Foo
<style name="Theme.MyApp.Foo" parent="Theme.MaterialComponents.Light">
<item name="customFooViewColor">@android:color/holo_orange_dark</item>
</style>
In :Features:Bar
<style name="Theme.MyApp.Bar" parent="Theme.MaterialComponents.Light">
<item name="customBarViewColor">@android:color/holo_green_light</item>
</style>
In :Features:Baz
<style name="Theme.MyApp.Baz" parent="Theme.MaterialComponents.Light">
<item name="customFooViewColor">@android:color/holo_orange_dark</item>
<item name="customBarViewColor">@android:color/holo_green_light</item>
</style>
Obviously this duplication of values is problematic because now I need to update values in multiple places whenever they change.
Is there a way to avoid the duplication without placing everything in :Ux? Has anyone written a build plugin that can achieve this?