Remove unused resources (drawables and layouts) from an Android project.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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