3

Yes, I saw that the similar question had been asked some years a go, but was unanswered, so I just had to give it another shot.

I am quite annoyed with the fact that the .apk file for the simple Android app I am building has 4MB in size.

When I analyse the .apk, i see that it contains not only unused classes (which can be stripped with ProGuard), but also all the graphic resources from HoloEverywhere.

I mean, even the drawables for the themes I am not using at all are in the apk.

This behaviour looks very illogical, or it just might be that I am doing something very wrong.

Finally, my question is: Is there a way to make the .APK contain only the needed data?

Howli
  • 12,291
  • 19
  • 47
  • 72
nebo.milic
  • 33
  • 3

1 Answers1

1

I mean, even the drawables for the themes I am not using at all are in the apk.

From the standpoint of the build tools, they have no good way of knowing that you are not using those drawables.

This behaviour looks very illogical

You are welcome to build a tool that can reliably detect unused resources and removes them from an APK. Call it ResGuard or something. Even the commercial DexGuard doesn't do this.

Is there a way to make the .APK contain only the needed data?

Delete the stuff that you are not using. You're the only one who knows what that is, and since HoloEverywhere appears to be no longer maintained, it's not like you will have updates to worry about.

Long-term, I understand that there's a plan to have Gradle for Android allow you to filter out resources as part of referencing an AAR. I'm not aware that this is in place just yet, and you'd still need to know what resources should be filtered this way. This would allow you to avoid modifying the original project, though.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • doesn't android Lint actually report unused drawables if configured to do so? – Droidman Aug 04 '14 at 22:23
  • @Droidman: Not from a library project AFAIK. Even if the code were integrated into the main project, it might not work if those drawables are referenced from a theme (even if that theme itself is presently unused). Moreover, you'd need some sort of override, akin to `-keep` in ProGuard, to handle cases where the detection algorithm fails (e.g., reflection). – CommonsWare Aug 04 '14 at 22:27
  • @CommonsWare:What you are suggesting is that I should manually remove the resources from the library projects? Yikes! – nebo.milic Aug 05 '14 at 07:49
  • @nebo.milic: "What you are suggesting is that I should manually remove the resources from the library projects?" -- yes. Or, remove HoloEverywhere entirely. Or, live with the APK file size. Or, live with the APK file size until such time as there is the ability, when referencing an artifact in Gradle for Android, to exclude certain resources as part of the compile step. – CommonsWare Aug 05 '14 at 10:44
  • @CommonsWare: Thanks for your answer. That makes this topic closed for me. – nebo.milic Aug 05 '14 at 11:52