I'm having a strange issue with shrinkResources . If I specify background to my drawable directly via attribute it works OK. But If I move it to style, shrinkResources starts to minify them, thinking that they are not used. It's not like I concatenate drawable file name in runtime which is hard to detect. It's a very broad case from my opinion.
Also I know that I can list all of my drawable in keep.xml
which prevents them from shrinking. But I have a lot of files and I plan to add them in the future as well which could lead to bugs in release (if I forget to add them). Is there another workaround?
styles.xml:
<style name="MyStyle">
<item name="android:background">@drawable/my_drawable</item>
</style>
my_layout.xml:
<Button style="@style/MyStyle" ... />
my_drawable.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle" >
<corners android:radius="25dip" />
<solid android:color="@android:color/white" />
</shape>
</item>
</selector>
./gradlew assembleRelease --info
:
Skipped unused resource res/drawable/my_drawable.xml: 1348 bytes (replaced with small dummy file of size 104 bytes)
and my_drawable.xml becomes:
<?xml version="1.0" encoding="utf-8"?>
<x />
For the sake of argument I specified: app/src/main/res/keep.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools"
tools:shrinkMode="safe" />