Android Lint Delete useless picture files and configuration files

Source: Internet
Author: User

Android Lint Delete useless, redundant profiles and picture resources

Reprint Please specify http://blog.csdn.net/aaawqqq?viewmode=contents


Android projects have a large number of useless Java classes and redundant images in a long-term iterative development project

If not collated will cause the APK package to be larger

Review cleanup Java classes use Ucdetector to see my previous blog post

http://blog.csdn.net/aaawqqq/article/details/46684441


Android Lint is a code checker provided by the Android SDK that primarily checks for profile resource files to find code issues

My usage scenario:

Reduce Android APK Package size

Use Android lint to discover useless pictures and XML files by removing redundant resources


What I'm here to share with you is tools and technology.

Specific knowledge you can see the reference link at the end of the article through other blog posts I'm not here anymore.


1) Tools1.1) Android lint in the Android SDK tools if you can expect everyone to be able to match environment variables .

This article takes the form of a command line to delete a batch of invalid resources


1.2) Another lint plugin in Eclipse

This method

Pros: Simple to run in Eclipse direct display

Cons: Need to manually delete when the number of redundant files is more suitable will be very nerve-racking


2) Input

Open the command line using the Lint command

:





Lint--check "Unusedresources"/users/baozi/dev/android/android > Result.txt

/users/baozi/dev/android/android > Result.txt

/users/baozi/dev/android/android is the path to the project (project name Android)

The resulting scan will be stored in the Result.txt in the current directory.

as in my directory /users/baozi/result.txt



3) output file Result.txt

Open File directory /users/baozi/result.txt





4) Delete the corresponding files in bulk according to the results


This article focuses on when you first run the discovery requires thousands of resource files need to be deleted when the headache

Manual deletion does not conform to the program ape Three excellent quality: lazy no patience pride


trying to use VIM to delete the discovery operation is also quite troublesome.  


You can refer to the following code using the file to get result.txt files in the information call to the filename. Delete (); Method Delete

/** * Delete unused redundant resources (picture XML layout) * * @param b * * False Display resource list * True show resource list and delete resource * * @throws EXCE ption */private static void init (Boolean B) throws Exception {string encoding = "UTF-8";//character format String ProjectPath = "/use Rs/baozi/dev/shihui/android/";//android Project address string filePath1 ="/users/baozi ";//result is located on the path file file = new file ( FilePath1, "Result.txt");//Get Result.txt file generation address if (File.isfile () && file.exists ()) {// Determine if the file exists inputstreamreader read = new InputStreamReader (new FileInputStream (file), encoding);//considering the encoding format BufferedReader BufferedReader = new BufferedReader (read); String line = Null;while ((line = Bufferedreader.readline ()) = null) {if (Line.contains ("unusedresources") &&!li Ne.contains ("Res/value") &&!line.contains ("AppCompat") &&!line.contains ("Res/xml")) {// System.out.println (line), int end = Line.indexof (":"), if (end! =-1) {String file_end = line.substring (0, end); String f = projectpath + file_end; System.out.println (f); if (b) {new File (f). Delete (); System.out.println ("delete succeeded");}}} Read.close ();}}


Projectpath:android the location of the project on the hard drive

Filepath1:lint where the run result Result.txt is located


Method parameter passed in false only prints the result in true prints and deletes the file


fill in the correct address to bulk execute delete unused layouts & picture resources (unusedresources)

If you want to remove other actions, modify the filter criteria

if (Line.contains ("unusedresources") &&!line.contains ("Res/value") &&! Line.contains ("AppCompat")

&&!line.contains ("Res/xml")



Usage Experience: 3-6 cycles can be used to complete the removal of all unused resources but some of the obsolete modules have code since the relationship needs to be manually determined to delete



attached 1:

How to review code using Eclipse's own Android lint plugin


How to use:

Right-click Project →android tools→run lint:check for Common Error

The results will show up in Lint warrings the same way you see Logcat.





Operation Result:




attached 2: Reference blog


http://blog.csdn.net/hudashi/article/details/8333349

http://xiaxveliang.blog.163.com/blog/static/29708034201272224352784/
http://mikewang.blog.51cto.com/3826268/1003276http://xiaxveliang.blog.163.com/blog/static/29708034201272224352784/
Android Lint Check Rule list http://hubingforever.blog.163.com/blog/static/17104057920121069261691///Introduction Clearer/HTTP// Www.cnblogs.com/0616--ataozhijia/p/3746260.html


The end is attached to the divine Beast

┏┓┏┓//┏┛┻━━━┛┻┓//┃┃//┃━┃//┃┳┛┗┳┃//┃┃//┃┻┃//┃┃//┗━┓┏━┛//  ┃┃   god beast bless  ┃┃   Code no bug!  ┃┗━━━┓//  ┃┣┓//  ┃┏┛//  ┗┓┓┏━┳┓┏┛//    ┃┫┫┃┫┫//    ┗┻┛┗┻┛

Daily diligence, hoping to help you.


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Android Lint Delete useless picture files and configuration files

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.