Android清除工程中無用資源文件的兩種方法
更新時間:2016年08月02日 17:20:47 作者:u011771755
這篇文章主要介紹了Android清除工程中無用資源文件的兩種方法,調(diào)用Android lint命令查找出無用資源,二是使用代碼自動刪除無用的文件,感興趣的小伙伴們可以參考一下
一、調(diào)用Android lint命令查找出沒有用到的資源,并生成一個清單列表:

命令:lint –check “UnusedResources” [project_path] > result.txt
執(zhí)行完之后會生成一個清單文件,內(nèi)容如下:

二、使用代碼自動刪除無用的文件:
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);
}
}
}
}
}
我們往往要多次重復(fù)執(zhí)行上面的操作,才能真正徹底的清除工程中無用的資源文件。
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Android 圖片縮放與旋轉(zhuǎn)的實現(xiàn)詳解
本篇文章是對在Android中實現(xiàn)圖片縮放與旋轉(zhuǎn)的方法進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-06-06
Android PopupWindow實現(xiàn)微信右上角的彈出菜單
這篇文章主要為大家詳細(xì)介紹了Android PopupWindow實現(xiàn)微信右上角的彈出菜單,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2018-04-04
Android 應(yīng)用更換皮膚實現(xiàn)方法
本文主要介紹Android 應(yīng)用更換皮膚,Android應(yīng)用如果想更換皮膚這里幫大家整理了相關(guān)資料,有需要的小伙伴可以參考下2016-08-08

