Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove unused resources from libraries?

At first I know Remove all unused resources from an android project, but that is only for projects.

I want to remove unused images from a library like the Google Play Services or the Wearable SDK. I already know that I can remove unwanted languages in gradle by using resConfigs, but I don't know how to remove images and layouts which I don't use. Is there any way to avoid that they are added?

like image 622
rekire Avatar asked Sep 15 '14 07:09

rekire


People also ask

How do I get rid of unused Drawables on Android?

In Android Studio Menu > Refactor > Remove Unused Resources... Select the resources you want to remove. You can exclude resources you want to keep by right-clicking on the resource item. Use Do Refactor to remove all Resources at once.

Should unused code be removed?

“You should be constantly looking to improve your codebase, including removing dead code.” “If you have those processes in place, you should be constantly looking to improve your codebase, including removing dead code,” he said.


2 Answers

I almost missed it to write that there is now a nice solution:

android {
    buildTypes {
        release {
            minifyEnabled true
            shrinkResources true
        }
    }
}

This was annouced on Google+ by Tor Norbye for the build tools version 0.14.0

like image 192
rekire Avatar answered Oct 31 '22 00:10

rekire


Probbably all you need to know about that is in this very good article from Cyril Mottier : http://cyrilmottier.com/2014/08/26/putting-your-apks-on-diet/

Read the part about Lint ("Use Lint extensively"), as it's the tool that allow you to remove unused resources.

Hope it helps...

like image 36
alocaly Avatar answered Oct 31 '22 01:10

alocaly