Android Lint

3 MIN READ

There are many tools for writing android code but i like to prefer Android Studio.

Question is that why? why should we use android studio for development?

The best part of android studio is the support that it provided to developers like auto-suggestion, ease to use and improve our code quality by using feature “Lint tools”.

Now the again, question is that what is lint? how can we use this tool? so in this blog we will discuss following topics:

1. Introduction

2. When to use?

3. Configuration

Introduction Lint:

Lint is a code scanning tool provided by Android Studio for identifying, suggesting, and correcting wrong or risky code present in the project. 

When to use it?

If you want to check every file of your code and make it less buggy without any extra manual effort, you can use Lint.

Using Lint, you can examine each file of your code to find errors, and Lint will identify the errors and suggest solutions. Errors or warnings can be:

  1. Unhandled Exceptions
  2. Unused variables
  3. Unused imports in file etc.

Configuration:

By using Android Studio, you can manually configure the list of issues to be configured by Lint or you can add Lint inspection to the lint.xml file or use Lint inspection in the lint.xml file.

In this blog we will understand how can we configure using the lint.xml file:

Create a lint.xml file and put it into the root directory of your Android project.

<?xml version=”1.0″ encoding=”UTF-8″?>

<lint>

<!– Disable the given check in this project –>

<issue id=”IconMissingDensityFolder” severity=”ignore” />

<!– Ignore the ObsoleteLayoutParam issue in the specified files –>

<issue id=”ObsoleteLayoutParam”>

<ignore path=”res/layout/activation.xml” />

<ignore path=”res/layout-xlarge/activation.xml” />

</issue>

<!– Change the severity of hardcoded strings to “error” –>

<issue id=”HardcodedText” severity=”error” />

</lint>

then put this code into the android tag of the build.gradle file:

lintOptions {

lintConfig rootProject.file(‘lint.xml’) // lint.xml file path

}

Now when running your code will get an error if you put any hardcode text into the layout file.

if you want to run default lint errors which are provided by Android Studio so you can follow the steps below:

Click Files > Settings > Editor > Inspections and then tick the issue checks you want the lint to perform

Thanks for reading this blog. In the next blog, we will learn how can we create a custom file for lint check.Using Lint, you can examine each file of your code to find errors, and Lint will identify the errors and suggest solutions. Errors or warnings can be:By using Android Studio, you can manually configure the list of issues to be configured by Lint or you can add Lint inspection to the lint.xml file or use Lint inspection in the lint.xml file.

Contact Us