Exploration of idea for removing duplicate resources using Android Lint

Source: Internet
Author: User

Exploration of idea for removing duplicate resources using Android Lint

Android Lint is a good check tool that helps developers check many problems. It is useful to check duplicate resource files of android projects.


1. Use

Android Lint has many commands, which can be found on the Internet. Check is mainly used today. The purpose of this command is to check only one or several types of resources, for example, to check useless resources "lint -- check UnusedResources ". You can enter the "lint -- list" command to view the types of checks, or enter the "lint -- show" command to view details. We can also save the result as a file so that we can view it. Below is a simple example:

Lint -- simplehtml -- Check UnusedResources

In this way, you can check duplicate resources in a project and save the results as html files for ease of viewing (the file path does not need to be enclosed in quotation marks ).


2. idea

There are lint plug-ins in eclipse, and there are many introductions on the Internet, but there are few idea-related documents. How can I use android lint in idea?

Right-click the project and choose "Analyze" --> "run inspaction by Name..." from the shortcut menu ...". In the displayed search window, enter the type of check to be executed, for example, "Unused Resources ". You do not have to enter all the information to find it automatically. After you click it, the "inspaction scope" selection window will pop up. Select the Check range. Generally, select the entire project or module. In the "inspaction scope" window, you can also set file filtering. Click OK to start checking. Then you can remove duplicate resources based on the check results.


3. The idea project check is incomplete.

Check the android project of idea is to find the problem, whether it is to use the command line or the built-in idea plug-in to check duplicate resources, according to the results, we can find that the check is not comprehensive, not to check the image resources. However, some documents on the Internet clearly indicate that lint can check image resources. What is the problem?

This is actually a problem with idea's android project structure. After idea creates an android project built, it will find R. java and other temporary files are actually empty, and the image resource check must be based on R. java file to check. So where is the real R. java file of the idea project?

Its location is "C: \ Users \ \. IntelliJIdea13 \ system \ compile-server \ \ Targets \ java-production \ \ Android \ generated_sources \ aapt \ \ R. java ".

I did a simple research and found a clumsy solution. For the command line and idea, the specific solution is somewhat different:

(1) Under the command line. Create the gen folder in the project, create the folder corresponding to the package name under it, and then copy R. java to the following. Then you can use lint for check. Because the default file structure of android is in the R. java file under gen, lint will go to this folder to find the R. java file.

(2) idea. The method is similar to the command line method. However, depending on the type of the created Project, the folders in R. java are also different. For example, the maven project will be under "target \ generated-sources \ r" (you want to know the R. java file location. You can right-click the project menu "open modules setting" --> "modules" and select "Android" under the corresponding module ", select the "Generated Sources" tab in the window on the right. The corresponding settings are displayed and can be modified .). Copy R. java to the corresponding folder and replace the empty R. java file. Then, check the image resources by using the lint of idea.

(3) idea maven. Idea is used to compile the android project. The R. java in the project directory is empty. However, if maven is used for compilation, a complete R. java file is generated under the directory, and you can directly lint the file. How to compile maven? First, the project is a maven project, and then select "edit deployments" in the running options on the toolbar ". In the pop-up "run/debug deployments" window, click "+" to add a maven item, define the name in the right column, and enter "clean compile" in "command line ". In this way, a running option is added, and then you can use maven to compile the project by selecting the newly added run option. This will generate a complete R. java file.


To sum up, idea projects may encounter problems. The reason is that idea has not put temporary files such as R. java in the project directory, which is also a special feature of idea. The above solution is also clumsy, and I don't know if there are more effective and convenient methods. If someone knows it, please give me some advice. Another file, the duplicate part of the styles. xml file, cannot be detected. Does anyone know what the problem is?

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.