I have the following bug while developing my app:
I'm building multiple app using some "default" library modules. Those library modules all use databinding and include default layouts and functionality. Sometimes I'll be required to change the UI of something found in the library modules and then I get into trouble.
Let's imagine the following scenario:
LibraryA:
Databinding enabled
Create LibActivityA and layout_A.xml (root tag is )
Inside LibActivityA use the LayoutABinding to your free will
AppB:
dependency on LibraryA
databinding enabled
Some activity inside AppB launches LibActivityA and everything works fine (no layout changes from LibraryA)
I do a release apk and can use it properly
AppC:
dependency on LibraryA
databinding enabled
I have a request to move an element found in layout_A.xml to the bottom of the screen let's say
I create another layout_A.xml file (root tag is ) and adjust what's needed (while keeping all other members to avoid runtime errors).
I run the app and at runtime I get a class cast exception
Quick search I find that the generated LayoutABinding is in my app package so I use https://developer.android.com/topic/libraries/data-binding/generated-binding#custom_binding_class_names to move LayoutABinding to the exact same package as found in LibraryA.
run the app again and everything is fine, champagne bottles out!
Hit generate signed apk to do a release build and get the following error: Execution failed for task ':app:transformDexArchiveWithDexMergerForVariantStoreRelease'.
com.android.build.api.transform.TransformException: java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: Learn how to resolve the issue at https://developer.android.com/studio/build/dependencies#duplicate_classes. Program type already present: com.company.librarya.databinding.LayoutABinding
I've searched the whole StackOverflow and internet and it seems nobody managed to successfully do what I want: overwrite the resource file from a library that uses dataBinding in order to have a slightly different view for some Apps that use the lib. Before using databinding everything went smoothly, indeed I had to be sure findViewByIds didn't return null and so but I could use the new layouts.