Android clears useless resource files and android resource files from the project.
1. Call the Android lint command to find useful resources and generate a list:
Command: lint-check "UnusedResources" [project_path]> result.txt
After execution, a configuration file is generated. The content is as follows:
Ii. Use the code to automatically delete useless files:
Public class DelAction {public static void main (String [] args) throws IOException {String projectPath = "***"; bufferedReader reader = new BufferedReader (new FileReader ("result path"); String line; int count = 0; while (line = reader. readLine ())! = Null) {if (line. contains ("UnusedResources ")&&! Line. contains ("res/value ")&&! Line. contains ("appcompat") {count ++; int end = line. indexOf (":"); if (end! =-1) {String file = line. substring (0, end); String f = projectPath + file; boolean flag = new File ("[complete file path]" + f. replace ("***","")). delete (); System. out. println ("[complete file path]" + f + "=> del =>" + flag );}}}}}
We often need to repeat the above operations multiple times to completely clear useless resource files in the project.