0

i have made a library where i am using a refs.xml files in the values folder, which overrides a material resource file using tools:override to be able to rearrange the dialog buttons.

<resources xmlns:tools="http://schemas.android.com/tools">
    <item name="mtrl_alert_dialog_actions" type="layout" tools:override="true">@layout/mtrl_alert_dialog_actions_custom</item>
</resources>

Using this library and building the app in debug mode without shrinking the resources, everything works properly. As soon as i enable resource shrinking, the refs.xml file is removed or not considered anymore.

When i place the refs.xml inside my app, the mtrl_alert_dialog_actions is overriden by mtrl_alert_dialog_actions_custom too.

But how can i achieve that i do not need to place the refs.xml file inside my app and tell the app to use the refs.xml file from the library when shrinkResources is enabled?

The build outputs do not mention anything that the refs.xml from the library is removed.

Aaron Falk
  • 113
  • 1
  • 4
  • All the unused library resource will be discarded when it is not used during compile time and resource shrinking is enabled by default. – Android Newbie A Jan 12 '23 at 08:31
  • In order to retain the unused resource, you will need to add `tools:keep` flag. https://developer.android.com/studio/write/tool-attributes#toolskeep – Android Newbie A Jan 12 '23 at 08:31
  • But where do i have to add the tools:keep flag? nearby the tools:override inside the refs.xml file? – Aaron Falk Jan 12 '23 at 09:17
  • I tried to add a res/raw/keep.xml file in the library and add the tools:keep for mtrl_alert_dialog_actions_custom, mtrl_alert_dialog_actions and mtrl_alert_dialog. It does not work. The only thing that works is to add the res/raw/refs.xml file in the app. and i am not happy with that – Aaron Falk Jan 12 '23 at 09:38

0 Answers0