Remove all unused resources from an android project
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.
Introduction
Unused drawables, layouts, strings, and raw assets make Android projects harder to maintain and can increase APK or App Bundle size. The safe way to remove them is not by deleting files blindly, but by combining static analysis, build-time shrinking, and a review of any resources loaded dynamically.
Start With Android Studio and Lint
Android Studio already knows how to look for unused resources. The built-in lint checks are usually the fastest first pass because they understand common references from layouts, manifests, navigation graphs, and generated R usage.
A practical workflow is:
- run lint on the module or whole project
- inspect
UnusedResourcesfindings - confirm whether any flagged resource is used dynamically
- delete or rename only after that review
From the command line:
Inside Android Studio, the same inspection is available through the code analysis tools. This catches a large percentage of dead resources without touching runtime behavior.
Use Resource Shrinking in Release Builds
Static analysis helps during development, but release builds should also shrink code and resources automatically. In Android builds, resource shrinking works together with code shrinking. If dead code is removed, resources that are reachable only from that dead code can be removed too.
Example in a Gradle Groovy build file:
This is important because some resources look used at source level but are only reachable through code that R8 later removes. Manual cleanup alone will miss that case.
Be Careful With Dynamic Resource Lookup
The main reason unused-resource cleanup goes wrong is dynamic lookup. If code constructs a resource name at runtime, static tools may not see the reference.
Example:
From the IDE’s point of view, none of the flag_* images may appear referenced directly. Deleting them would break the screen even though lint called them unused.
If you must use dynamic lookup, keep that list small and documented. Even better, replace string-based lookup with an explicit map so the references remain visible to both humans and tools.
That is easier to maintain and safer for shrinkers.
Keep Specific Resources When Needed
Sometimes a resource really is used indirectly and must survive shrinking. In that case, mark it explicitly instead of disabling shrinking globally.
One approach is a keep file using the Android tools namespace:
That tells the shrinker to preserve those resources even if static analysis cannot prove they are needed.
Clean Up More Than res/
Unused resources are not limited to drawable or layout. It is worth checking:
- duplicate strings that should be merged
- obsolete menu XML files
- old navigation graphs
- sample JSON or media files in
raworassets - alternative-density images no longer used by current UI
These files are easy to forget because they do not always trigger compiler errors.
Common Pitfalls
The biggest mistake is deleting resources after a lint run without checking for runtime lookup through getIdentifier, reflection, or third-party libraries.
Another issue is relying only on manual deletion and never enabling shrinkResources in release builds. That leaves easy size wins on the table.
A third problem is keeping large piles of old assets “just in case.” If a file matters, keep it for a documented reason. Otherwise it is technical debt.
Summary
- Use Android Studio lint as the first pass for finding unused resources.
- Enable
minifyEnabledandshrinkResourcesfor release builds. - Review dynamic resource lookups before deleting anything.
- Prefer explicit
R.drawableorR.layoutreferences over string-based lookup. - Keep special resources intentionally instead of disabling shrinking for the whole app.
Related reading
- Remove all whitespace in a string
- Remove data from tensorboard event files to make them smaller
- Remove duplicate objects from an array using javascript
- Remove elements from collection while iterating
- Remove background drawable programmatically in Android
- Remove Content and Frame layout guides from UIScrollview
- Remove last character of a StringBuilder?
- Remove multiple keys from Map in efficient way?

DSA Fundamentals
Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.