How can I force Proguard to keep my .xml resource file?

You shoud add a new file keep.xml under res/raw.

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools=""
    tools:discard="@layout/unused2" />

In tools:keep, you list the layouts you want to keep. You can even keep specefic drawables if you use reflection in your code to get your drawable


I prefer to add tools:shrinkMode="strict" so that I make sure no resource is eliminated unless it is not used for sure. You may want to have a look at this link Shrink your code.
Don’t Forget to add these lines to your proguard rules:

-keepattributes InnerClasses -keep class **.R -keep class **.R$* { <fields>; }

Leave a Comment