With the Android project, if you do not delete the useless resources in time to install the package will be more and more large, it is time to tidy up the discarded resources shrink package, young!
In fact, to determine whether a resource (drawable,layout) is not used very simple, the file name (does not include the suffix) to go to the document to look for the line, not found there is no use, directly deleted it can be
Python's string handling is relatively simple, and a script is written for you to refer to:
Import OS
Import Os.path
RootDir = ' D:\HitFm_v2.1.6\hitfm\src '
Pngfiles = []
Xmlfiles = []
Javafiles = []
Tempfiles = []
For Parent,dirnames,filenames in Os.walk (ROOTDIR):
For filename in filenames:
if (Filename.find ('. png ')! =-1):p Ngfiles.append (Os.path.join (parent,filename))
if (Filename.find ('. jpg ')! =-1):p Ngfiles.append (Os.path.join (parent,filename))
if (Filename.find ('. xml ')! =-1): Xmlfiles.append (Os.path.join (parent,filename))
if (Filename.find ('. java ')!! =-1): Javafiles.append (Os.path.join (parent,filename))
For Pngfile in pngfiles:
Pngname = pngfile.split (' \ \ ') [-1]
Pngnowname = Pngname.split ('. ') [0]
if (pngfile.find (' res ') = =-1): Continue
Bfind = False
for javafile in javafiles:
F = open (Javafile, ' RB ') br> javastr = F.read (). Decode ()
if (Javastr.find (pngnowname)! =-1): bfind = True
for xmlfile in xmlfiles:
F = o Pen (xmlfile, ' RB ')
Javastr = F.read (). Decode ()
if (Javastr.find (pngnowname)! =-1): bfind = True
if (bfind = = Fal SE):
print (pngfile)
Os.remove (pngfile)
For xmlfile in Xmlfiles:
XMLName = xmlfile.split (' \ \ ') [-1]
Xmlnowname = Xmlname.split ('. ') [0]
if (Xmlfile.find (' res ') = = =-1): Continue
bfind = False
For Javafile in Javafiles:
f = open (Javafile, ' RB ')
Javastr = F.read (). Decode ()
if (Javastr.find (xmlnowname)! =-1): Bfind = True
For XmlFile2 in Xmlfiles:
f = open (XmlFile2, ' RB ')
Javastr = F.read (). Decode ()
if (Javastr.find (xmlnowname)! =-1): Bfind = True
if (bfind = = False):
Print (xmlfile)
Tempfiles.append (xmlfile)
For Tempfile in Tempfiles:
Print (Tempfile)
Os.remove (Tempfile)
When using only need to change RootDir = ' D:\HitFm_v2.1.6\hitfm\src ' to their own code directory, the command line execution xx.py (need to install python3.0 above version of the interpreter)
Android Delete a Python script for a useless resource file