Android源码工具findunusedstrings寻找未使用字符串工具的学习和使用

56 篇文章 0 订阅
10 篇文章 1 订阅

工具路径: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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值