Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should we use this plugin multiple times to remove unused resources completely? #23

Open
jmatsu opened this issue May 15, 2018 · 1 comment
Milestone

Comments

@jmatsu
Copy link

jmatsu commented May 15, 2018

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 only xml_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.

@konifar
Copy link
Owner

konifar commented May 19, 2018

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...

@konifar konifar added this to the 1.0.0 milestone May 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants