then
appname=$(basename $app)
resources=
- for res in $(echo $app/res/*)
+ for res in $(echo $app/res/* $(find $ANDROID_BUILD_TOP/vendor -type d -wholename $ANDROID_BUILD_TOP/vendor/*/$appname/res | grep overlay))
do
resources="$resources $(echo $res | grep -v '\-mcc\|[a-z]*-[a-z][a-z]$\|[a-z]*-[a-z][a-z]-.*')"
done
# First take all the input files and concatenate them, removing newlines. This allows us to
# find expressions that are broken up over multiple lines, i.e. R.drawable.\nsomeconstant
- find $resources $sources $app/AndroidManifest.xml -name .git -prune -o -type f -print |xargs cat | tr -d '\n ' > /tmp/everything$$
+ find $resources $sources $app/AndroidManifest.xml -type f -print |xargs cat | tr -d '\n ' > /tmp/everything$$
# Now look for each of the constants in the contatenated file.
for i in $(cat $rDotJava | grep "\w*=0x\d*" | sed 's/ *public static final int //' | sed 's/=0x.*//')
# refer to such constants from java by using an underscore instead of a period, we also
# replace all underscores with a pattern that will match periods and underscores.
p=$(echo $i | sed 's/_/[\\._]/g')
- echo $i $(grep -cw R\\..*\\.$i\\\|@style/$p\\\|@drawable/$p\\\|@anim/$p\\\|@color/$p\\\|@xml/$p\\\|@layout/$p\\\|@menu/$p\\\|@+id/$p\\\|@array/$p\\\|@string/$p\\\|@dimen/$p < /tmp/everything$$)
+ echo $i $(grep -cw R\\..*\\.$i\\\|@style/$p\\\|@drawable/$p\\\|@anim/$p\\\|@color/$p\\\|@xml/$p\\\|@layout/$p\\\|@menu/$p\\\|@+id/$p\\\|@array/$p\\\|@string/$p\\\|@dimen/$p\\\|\[a-z\]\*:$p\\\|enumname=\"$p\\\|\<item\>$p\< < /tmp/everything$$)
done | grep " 0$" | {
# this block gets as its input a list of constants for which no references were found, one per line
if [ "$showall" == "yes" ]
--- /dev/null
+#!/bin/bash
+
+if ! which xmlstarlet > /dev/null
+then
+ echo "You need to have the 'xmlstarlet' command in your path"
+ exit
+fi
+
+apps=$1
+CWD=$(pwd)/
+if [ "$apps" = "" ]
+then
+ echo "Please specify the path to an application, or '--all' to process all applications"
+ exit
+elif [ "$apps" = "--all" ]
+then
+ apps=$ANDROID_BUILD_TOP/packages/apps/*
+fi
+
+BASE=$(pwd)/$(dirname $0)
+
+for app in $apps
+do
+ pushd $app
+ $BASE/findunusedresources -p . | {
+ read LINE NUM
+ while [ "$LINE" != "" ]
+ do
+ if [ "Z$LINE" = "Z-----------------------------------------------------------" ]
+ then
+ # skip
+ true
+ elif [ "$LINE" = "$app" ]
+ then
+ # skip
+ true
+ else
+ # try to find the missing resource
+ find res | grep -w $LINE | {
+ read RESLINE
+ while [ "$RESLINE" != "" ]
+ do
+ if [ -f $RESLINE ]
+ then
+ echo REMOVING FILE: $RESLINE
+ git rm $RESLINE > /dev/null
+ else
+ echo WARNING unexpected result for $LINE
+ fi
+ read RESLINE
+ done
+ }
+ grep -Rwl $LINE res | {
+ read RESLINE
+ while [ "$RESLINE" != "" ]
+ do
+ ISSTRING=$(echo "$RESLINE" | grep -w "strings\.xml")
+ if [ -n "$ISSTRING" ]
+ then
+ echo REMOVING STRING $LINE from $RESLINE
+ xmlstarlet ed -P -S -d "/resources/string[@name='$LINE']" $RESLINE > tf$$
+ mv tf$$ $RESLINE
+ git add $RESLINE
+ else
+ echo REMOVING $LINE from $RESLINE
+ xmlstarlet ed -P -S -d "/resources/*[@name='$LINE']" $RESLINE > tf$$
+ mv tf$$ $RESLINE
+ git add $RESLINE
+ fi
+ read RESLINE
+ done
+ }
+ fi
+ read LINE NUM
+ done
+ }
+ popd
+done
+echo
+echo "Done."
+echo "Please rebuild the updated applications to make sure that everything still builds."
+echo "After rebuilding, rerun 'findunusedresources' or 'removeunusedresources' to see if any more resources are now unused."
+echo "When you're done, you can 'git commit' the change."
+echo