Skip to content

Instantly share code, notes, and snippets.

@calvarez-ov
Last active February 16, 2016 16:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save calvarez-ov/194123c6e81f636b8e48 to your computer and use it in GitHub Desktop.
Save calvarez-ov/194123c6e81f636b8e48 to your computer and use it in GitHub Desktop.
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