Two ways to eliminate useless resource files in Android project _android

Source: Internet
Author: User

First, call the Android Lint command to find out which resources are not used and generate a list of listings:


Command:lint–check "Unusedresources" [Project_path] > Result.txt
after execution, a manifest file is generated, which reads as follows:

Use code to automatically delete useless files:

public class Delaction
{public
  static void Main (string[] args)
    throws IOException
  {
    String ProjectPath = "* * *";
    BufferedReader reader = new BufferedReader (new FileReader ("Result path"));
    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 ("spelling out the full path of the file" "+ F.replace (" * * * ")). Delete ();          System.out.println ("" "spelling out the full path of the file" "+ F +" =>del=> "+ Flag);}}}}

We often have to repeat the above operation many times in order to truly eliminate the useless resource files in the project.

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.