源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

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

  • 时间:2022-11-26 05:54 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:Android清除工程中无用资源文件的两种方法
[b]一、调用Android lint命令查找出没有用到的资源,并生成一个清单列表:[/b] [img]http://files.jb51.net/file_images/article/201608/201682170120435.jpg?20167217146[/img] 命令:lint –check “UnusedResources” [project_path] > result.txt 执行完之后会生成一个清单文件,内容如下: [img]http://files.jb51.net/file_images/article/201608/201682170202716.jpg?20167217211[/img] [b]二、使用代码自动删除无用的文件:[/b]
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);
        }
      }
    }
  }
}
我们往往要多次重复执行上面的操作,才能真正彻底的清除工程中无用的资源文件。 以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程素材网。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部