Remove all unused resources from an android project

Viewed 207764

I want to remove all unused layouts, strings, drawables, colors, etc from my Android res directory. Are there any tools that will give me a list of files and I can remove from my repository and elements within specifics files (e.g. unused string entries) that are no longer used?

17 Answers

In Android Studio,

Analyze -> Run Inspection by Name

(Shortcut For Mac shift+command+option+i , Ctrl + Shift + A on Windows/Linux).

And type 'unused resources'.

This way you can remove unused resources, variables ,symbols ,localization ,libraries ..etc.

Select the desired inspection from the list, then select inspection scope ->OK enter image description here

1--> In

Android Studio Menu > Refactor > Remove Unused Resources

As Shown in Image Below:

enter image description here

**

OR

**

2--> Second Way

-> Ctrl Alt Shift i and type "unused resources" (without quotes) in Windows

-> use ⌘ Option Shift i for mac

or

-> cmd + Alt + Shift for mac

shift double click on Windows then type "unused", you will find an option Remove unused Resources,
also

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

when you set these settings on, AS will automatically remove unused resources.

Related