gradle-unused-resources-remover-plugin
gradle-unused-resources-remover-plugin copied to clipboard
Should we use this plugin multiple times to remove unused resources completely?
Thank you for providing a wonderful plugin! :)
BTW, should I run removeUnusedResources
task twice or more to assure Completed?
In our case, it's not enough to remove resources by running removeUnusedResources
only once due to a reference graph.
(These examples are just based on my quick look so that other cases might exist.)
Simple reference case in value-grained Remover
...
<color name="referencer_color">@color/referenced_color</color>
<color name="referenced_color">#FFFFFF</color>
...
For example, you should assume that referenced_color
is referenced from only one code, i.e. referencer_color, and referencer_color
is not referenced from anywhere.
Then, referencer_color
must be removed and this plugin does behave like so. :) After removing that, referenced_color
's reference count would be changed from 1 to 0 so that this plugin should remove referenced_color
too.
So kinda reference count concept should be considered during removing.
More complex reference case across file-grained and value-grained Removers
# in drawable/xml_drawable.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/jpg_drawable"/>
</selector>
# in values/styles.xml
<style name="StyleSample">
<item name="android:background">@drawable/xml_drawable</item>
</style>
Let's say:
-
drawable/jpg_drawable.jpg
is available -
drawable/jpg_drawable.jpg
is referenced from onlyxml_drawable
-
xml_drawable
is referenced from only StyleSample - StyleSample is not referenced from anywhere.
Run a task once, then StyleSample should be removed (of course, your plugin works fine! ). After that, run a task again, then xml_drawable
would be removed. Again, drawable/jpg_drawable.jpg
would be removed.
Files, which would be marked as unused
after removing values, cannot be removed by running a task once. Because file removers are run before value removers.
Thanks for your report and sorry for late response! I know what you mean. Let me consider how to solve this issue 🤔
One easy option is to run several time. But it takes too much time to finish task. I guess other option would make logic complex. So I'm thinking how this should be fixed...