当前位置: 移动技术网 > IT编程>移动开发>Android > Android清除工程中无用资源文件的两种方法

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

2019年07月24日  | 移动技术网IT编程  | 我要评论

揭开黎明之光的秘密,刘润民,贵霜帝国

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

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

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

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网