Part 2: High-quality android code with analysis tools : Lint
Android Lint is a analysic tool to easily identify and correct problems with the structural quality of your code, without having to execute the app or write any test cases. This tool improves the accuracy, security, performance, usability, as well as simple source code making it easier for people to read your source code. So I want through this article to share with you how to use a tool that is useful Android Lint.
1.What is Android Lint tool?
Android Lint is a static code analysis tool developed based on Lint (a well-known code analysis tool available in many languages such as C / C ++, JAVA, PHP, …) and customized to analyze source code of Android projects.
— Find potential error, handle it and optimize code.
— Improving accuracy, security, performance, reusability, as well as simplified source code make it easier for anyone to read and understand your source code.
— Make your code standard Google.
Just like other lint tools, Android Lint also uses the checker system to analyze and detect potential bugs within the source code. Perhaps you do not know what the checker is so I also explain, checker is the rule that your source code must comply. And Android Lint also includes a lot of checkers provided by Google. You can also assume that Android Lint is a tool that Google provides to you so that you can follow the code rules that Google set out to achieve the best effect.
2. How it works
Below figure shows how the
lint tool processes the application source files.
Figure 1. Code scanning workflow with the
Application source files The source files consist of files that make up your Android project, including Java and XML files, icons, and ProGuard configuration files. The
lint.xml file A configuration file that you can use to specify any
lint checks that you want to exclude and to customize problem severity levels. The
lint tool A static code scanning tool that you can run on your Android project from the command-line or from Eclipse. The
lint tool checks for structural code problems that could affect the quality and performance of your Android application. It is strongly recommended that you correct any errors that
lint detects before publishing your application. Results of
lint checking You can view the results from
lint in the console or in the Lint Warnings view in Eclipse. Each issue is identified by the location in the source files where it occurred and a description of the issue.
3. How to use Android Lint
Step 1: Open project and select project → Anlyze → Inspect Code :
Step 2: Choose directory to analyze and check or uncheck rule in rule table :
Step 3: After the tool run complete, you can check result in Inspection Result tab, you can check out the issues that Android Lint has detected in the source code of the project and fix if necessary.
You can also see the Inspect window (Android Lint) is divided into two parts:
The left side is a list of issues Android Lint finds in your source code. When you double click on a problem in this section, the code window above will jump to the problematic position in the source code.
The right part is the detail of the problem you are choosing. This section will include a detailed location and description of the problem as well as suggestions on how to fix it (in the Suppress section).
With this tool you can avoid potential bugs, increase code quality and your code will follow Google standards. After this article, I hope you will have a handy tool for improving your skills. Hope you will support me in the next post. Thank you for reading this post!
You can follow thientvse to update new post about technology.
Originally published at Code for fun.