liyujie
2025-08-29 87c7c0d90966d729ca3d39cbfca77a39a43960eb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/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
    fi
done