shrink resources does not work for libraries modules

1.1k views Asked by At

I have some library modules in my application and there are a lot of resources that are unused. But they did not remove in release build.

minifyEnabled has been set true in release buildType and also shrinkResources has set true in app module.

Note: Proguard worked correctly and remove all of the unused source codes.(including library module source codes).

P.S: I know that we can't use shrinkResources option in library modules and this shrinking is app module responsibility.

UPDATE1 : I read this thread's answers. Although I didn't use getIdentifier(), it hasn't effect.

UPDATE2: According to below quote, I checked R class in output apk and I found references(id) to unused resources. Why are they there?

Proguard works on the Java side. Unfortunately, it doesn’t work on the resources side. As a consequence, if an image my_image in res/drawable is not used, Proguard only strips it’s reference in the R class but keeps the associated image in place. source

1

There are 1 answers

1
Fartab On

I checked shrinkResources option and it works somehow. shrinkResources did not remove unused resources rather it clears file contents. For unused xml I saw an empty xml like this in the output apk:

<?xml version="1.0" encoding="utf-8"?>
<x />

I don't know the reason behind clearing content instead of deleting the file.
This approach is not optimal but is acceptable. An empty xml like the above one occupies 47 bytes.