Skip to content

Instantly share code, notes, and snippets.

@calvarez-ov
Last active February 16, 2016 16:42
Embed
What would you like to do?
Remove unused resources (drawables and layouts) from an Android project.
remove_unused_resources() {
TAG=$1 # Just for logging
RESOURCE_PATH=$2
EXTENSION=$3
echo
echo $TAG
for file in $RESOURCE_PATH*/*.$EXTENSION
do
# strip the extension
bname=`basename $file .$EXTENSION`
bname=`basename $bname .9` # hack for *.9.png and *.png
# Check if the resource is referenced anywhere
git grep -c $bname > /dev/null
# If the resource isn't referenced, remove it
if [ $? -eq 1 ]
then
echo "$file ($bname)"
git rm $file
fi
done
}
remove_unused_resources "drawable xml" src/main/res/drawable xml
remove_unused_resources "drawable png" src/main/res/drawable png
remove_unused_resources "layout" src/main/res/layout xml
remove_unused_resources "menu" src/main/res/menu xml
remove_unused_resources "anim" src/main/res/anim xml
remove_unused_resources "xml" src/main/res/anim xml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment