工具路径:aosp/development/tools/findunused/findunusedstrings
使用方法:
./development/tools/findunused/findunusedstrings -p vendor/sprd/platform/packages/apps/Tag
结果:
action_call 0
action_text 0
button_done 0
call_phone_permission_denied 0
empty_tag_prompt 0
external_storage_permission_denied 0
import_vcard 0
mime_display_name 0
tag_empty 0
tag_unknown 0
title_existing_tag 0
title_scanned_tag 0
vcard_title 0
./development/tools/findunused/findunusedstrings: line 48: popd: vendor/sprd/platform/packages/apps/Tag: invalid argument
popd: usage: popd [-n] [+N | -N]
上面的结果就是未被使用的字符串
这里有一个问题说 popd 后面跟的参数不对,只要把源码中 popd 后面的 $app 参数删除即可,不过不删除影响也不是很大,我们一般一次也只对一个路径做pushd
findunusedstrings 的源码如下:
#!/bin/bash
if [ "$1" == "-h" ]
then
cat <<- EOH
Usage: $0 [-p] [folder]
-p option prints out unused strings, otherwise a total count is printed
folder option causes only that app folder to be scanned, default is to scan all folders onder apps/
EOH
exit
fi
showall=no
if [ "$1" == "-p" ]
then
showall=yes
shift
fi
apps=$1
if [ "$apps" == "" ]
then
apps=$ANDROID_BUILD_TOP/packages/apps/*
fi
for app in $apps
do
if [ -d $app/res ]
then
pushd $app > /dev/null
# Two sed's were needed because the | operator is not supported on the mac
for i in $(grep -Rs "\(string\|plurals\) name=" res | sed 's/.*string name=\"//' | sed 's/.*plurals name=\"//'|sed 's/".*$//'|sort -u)
do
echo $i $(grep -Rws R.plurals.$i\\\|R.string.$i\\\|@string/$i .|wc -l)
done | grep ' 0$' | {
if [ "$showall" == "yes" ]
then
echo $app
cat
else
count=$(wc -l)
if [ "$count" != "0" ]
then
echo $app: $count unused strings
fi
fi
}
popd $app > /dev/null # 这个可以把 $app 删掉
fi
done