歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Android刪除工程中無用的資源文件

Android刪除工程中無用的資源文件

日期:2017/3/1 9:27:00   编辑:Linux編程

一、調用Android lint命令查找出沒有用到的資源,並生成一個清單列表:

命令:lint –check “UnusedResources” [project_path] > result.txt

執行完之後會生成一個清單文件,內容如下:

二、使用代碼自動刪除無用的文件:

public class DelAction
{
public static void main(String[] args)
throws IOException
{
String projectPath = "***";
BufferedReader reader = new BufferedReader(new FileReader("result路徑"));
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("【拼出文件完整路徑】" + f.replace("***", "")).delete(); System.out.println("【拼出文件完整路徑】" + f + "=>del=>" + flag);
}
}
}
}
}

我們往往要多次重復執行上面的操作,才能真正徹底的清除工程中無用的資源文件。

更多Android相關信息見Android 專題頁面 http://www.linuxidc.com/topicnews.aspx?tid=11

Copyright © Linux教程網 All Rights Reserved