欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

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

程序员文章站 2024-03-06 18:05:08
一、调用android lint命令查找出没有用到的资源,并生成一个清单列表: 命令:lint –check “unusedresources” [project...

一、调用android lint命令查找出没有用到的资源,并生成一个清单列表:

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

命令:lint –check “unusedresources” [project_path] > result.txt
执行完之后会生成一个清单文件,内容如下:

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

二、使用代码自动删除无用的文件:

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);
        }
      }
    }
  }
}

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

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