The main content

Configure Lint to scan scope and check items using the tools provided with Android Studio. In improving your code documentation with Lint, this is a manual run check.

Program static analysis

Program static analysis refers to a code analysis technology that scans program code through lexical analysis, syntax analysis, control flow analysis, data flow analysis and other techniques without running the code to verify whether the code meets the norms, security, reliability, maintainability and other indicators.

Java-android code analysis tools commonly used

  • Checkstyle
  • FindBugs
  • Soot
  • Lint

Use Lint to improve your code

Lint is a code scanning tool provided by Android Studio that automatically scans code to help improve the standardization and maintainability of code structures and improve the quality of code.

Lint static scanning works as shown in the following figure.

How to operate Lint in Android Studio

Android Stuido Lint provides the Specify Inspection Scope panel, where you can personalize code scanning tasks.

Open theSpecify Inspection ScopePanel: Menu bar ->Analyze->Inspect Code

Set the scan Scope Custom Scope

  • You can configure the range that Lint can scan in the panel, where the File option displays three states based on where the cursor is before the panel pops up:
  • Files: Bring up the panel on the open file, you can scan the current open file;
  • Directory: Select the Directory in the Project panel to bring up the panel, and scan the selected Directory;
  • Hidden: This option is not provided
  • Personalized scan range setting
  • You can select an existing custom scan configuration from the drop-down list box on the right of the title
  • The “… “on the right of the drop-down box Button to raise the customized scan configuration panel and add or delete the source files to be scanned for any configuration. The left column is a list of custom configurations that will appear in the drop-down box at the next level.

After setting, generate the corresponding configuration files and run them in the. Idea /scopes directory

Check Item Settings

The final Inspection Profile on the Specify Inspection Scope panel specifies which issues to check during a code scan. The system provides only one Default option by Default. You can click “… “on the right of the drop-down box. Button to add personalized options.

  • As shown in the picture below, we need to Copy the Default configuration item to Project first, and then we can edit it on the newly generated configuration item after changing it to a lovely name.

The first step is to click on the eraser (covered by the popup box), clear all the options copied from Default, and then select the appropriate set as needed.

Android, General, XML, and Spelling are mandatory. If only Java code exists in the project, you only need to check the Java option. Otherwise, you may need to check kotlin, FLUTTER, DART, and other related options.

In addition, the above mentioned options, there are many sub-options, not all of them are necessary, you can select a part of the options to check.

After the configuration is complete, the corresponding configuration file is generated and stored in the. Idea /inspectionProfiles directory

  • Problem Warning Level

Select check items to set an option. The description and security alert level are displayed on the right. Android Studio Lint provides six levels of security tips, each with a different appearance, importance and visibility.

Once you have set the desired options, click OK in the lower right corner to use the set of Settings.

Perform Lint static scan & view the results

After the scan range and check items are set, you can perform the static scan. Click the “OK” button in the lower right corner of the Specify Inspection Scope panel to begin the scan operation. After the scan is complete, the Inspection Results panel will pop up at the bottom of Android Studio, which can be categorized according to the security level or check items. From here, we can organize and modify the code according to the scan Results.

Refer to the article

  • Static code analysis tool list analysis
  • Use Lint to improve your code