栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 移动开发 > Android

Android清除工程中无用资源文件的两种方法

Android 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Android清除工程中无用资源文件的两种方法

一、调用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);
 }
      }
    }
  }
}

我们往往要多次重复执行上面的操作,才能真正彻底的清除工程中无用的资源文件。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持考高分网。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/161965.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号