How to filter redundant resource files in Android project _android

Source: Internet
Author: User
Tags tmp file

This article is an example of the filtering of the Android project redundant resources file solution, very practical value! The detailed description is as follows:

Many developers often experience this in the development process of Android projects: interface developers released a new version of the resource bundle, but some of the image name changed, and some pictures were deleted, but in the implementation of the developer just the new resources to cover the original folder, with the release of the release, More and more useless resources accumulate in drawable or values, until the final release of the official version of the want to delete these redundant files, so you have to check a file to see if it is useful, and then decide whether to delete it.

In view of this, it is necessary to automate this process of detection!

To deal with this type of problem, you should first think of the shell script, the following is a use of the shell to automatically detect the file is not used, and to implement the automatic deletion of unused files function:

#!/bin/sh
resfile=result.txt
#drawdir =res/layout
drawdir=res/drawable-hdpi
tmpdrawfile= " Tmpdraw.txt "
#clear tmp file
echo" "> $tmpdrawfile
echo" "> $resfile
ls $drawdir > $tmpdrawfil E
#ls $tmpdrawfile
cat $tmpdrawfile | While read line
do
filename= ' echo $line | sed ' s/. *//'
#echo $filename
#start to search
grepdir=./res
#grepMode =r.layout. $filename
#grepDir =./com
result= ' grep-r $grepMode $grepDir '
if [' $result ' = ' "]
then
Echo $line
echo $line >> $resfile
rm-f $drawdir/$line
#else
# echo "----------------"
fi
Done
rm-f $tmpdrawfile

The above code is very simple, first of all the drawable (or you can change to any directory) under all the files listed, and then traverse the entire directory, for each file detection there is no ' @drawable/$ FileName ' The use of this format (you can change to any format yourself), if not used, the file will be deleted. This script needs to be placed in a directory with the Res sibling.

This code can also be used in any other place where there is a need to detect unused/used files, as long as the corresponding directories and matching patterns are modified, or if, for general purposes, all configurations can be written in a single configuration file, or the configuration can be passed in as parameters.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.