1

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

beigirad
  • 4,986
  • 2
  • 29
  • 52

1 Answers1

1

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.

Fartab
  • 4,725
  • 2
  • 26
  • 39
  • What the hell is going on? :/ Most of our unused resources are `.png` files and according to your answer, some of them converted to 1x1 pixel black png. but I can find a lot of unchanged png files in apk. – beigirad Dec 23 '19 at 09:11