android -------- Lint optimization tool

What is Lint

Lint is a code scanning analysis tool provided by Android Studio  , which can help us find code structure/quality problems and provide some solutions, and this process does not require us to write test cases.

Each problem found by Lint has a description and level (similar to bugs found by testing), and we can easily locate the problem and solve it according to the severity.

Of course, this "severity" can be adjusted manually. Some principles cannot be violated and must be upgraded to error, and some individual problems can be ignored.

A brief introduction to how Lint works

Lint will check the source files of our Android project according to the pre-configured detection standards, and find potential bugs or places that can be optimized. The optimization content mainly includes the following aspects:

  • Correctness: not perfect coding, such as hard coding, using outdated API, etc.
  • Performance: Coding that affects performance, such as: static references, circular references, etc.
  • Internationalization: Internationalization, using Chinese characters directly, without using resource references, etc.
  • Security: Insecure coding, such as allowing the use of JavaScriptInterface in WebView, etc.

 

Scope of Analysis

To statically analyze an Android project, the first step is to specify the range of source files to analyze. Including the following aspects:

  1. The entire project or module.
  2. directories and files.
  3. Use tags and annotations in xml and java files to ignore checks.
  4. The lint check result is divided into two levels: warning and error, and the warning problem can be ignored.

 

Lint usage path:  
Toolbar -> Analyze -> Inspect Code…

After clicking  Inspect Code  , a dialog box for the inspection scope will pop up:

 

 

The default is to check the entire project, we can click  Custom scope  to customize the scope of inspection.

Click the drop-down box on the right, and the following options will appear:

 

Respectively:

  • Project Files: All project files
  • Project Production Files: The code files for the project
  • Project Test Files: Test files for the project
  • OpenFiles: currently open files
  • Module 'app': the main app module
  • Current File: the current file

Click OK to check and display the check result

 

Using lint for code inspection and analysis is very simple and efficient. Before releasing the version, it is better to use lint to optimize the project.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324465801&siteId=291194637