: In ADT 17, you can also ignore warnings using annotations (in Java files) and using special attributes (in XML files). See this blog entry
for more details.
While Lint can often find real errors that must be fixed, it also flags issues that may or may not be a problem depending on the context. If you've manually verified that an issue is not a problem, you may want to mark the issue as verified such that lint does not keep pointing it out.
From the Command Line
The lint command has three commands for controlling which checks are performed:
(see the overview document
for more details on these flags). However, these must be specified each time you run lint.
To persistently configure which rules are run, you can create a file named
lint.xml in the root directory of your project (next to the manifest file). Lint will automatically look at this file and use it to ignore warnings. Note that when you use Eclipse to suppress errors, it automatically creates this file for you, so you can use Eclipse to ignore warnings and then check in the resulting configuration file such that for example build server lint runs will ignore warnings you've manually verified.
Here's a sample lint.xml file (the comments are obviously not needed; I've added them here to explain what each line does)
<?xml version="1.0" encoding="UTF-8"?>
Disable the given check in this project
<issue id="IconMissingDensityFolder" severity="ignore" />
Ignore the ObsoleteLayoutParam issue in the
<ignore path="res/layout/activation.xml" />
<ignore path="res/layout-xlarge/activation.xml" />
Ignore the UselessLeaf issue in the given file
<ignore path="res/layout/main.xml" />
Change the severity of hardcoded strings
<issue id="HardcodedText" severity="error" />
The issue identifiers here (IconMissingDensityFolder, ObsoleteLayoutParam etc) are the issue ids, which are included in the error output from the lint command:
Warning: The resource R.drawable.robot appears to be unused [UnusedResources]
You can also look up the lint ids with the
command (for full details) or
(for a brief summary):
$ lint --list
"ContentDescription": Ensures that image widgets provide a contentDescription
"DuplicateIncludedIds": Checks for duplicate ids across layouts that are
combined with include tags
"DuplicateIds": Checks for duplicate ids within a single layout
"StateListReachable": Looks for unreachable states in a <selector>
"InefficientWeight": Looks for inefficient weight declarations in
"NestedWeights": Looks for nested layout weights, which are costly
This lint configuration file apply to the current project, as well as any library projects included into this project. If you want to also have a "global" configuration used for all projects, you can create an additional global file and then invoke lint with the
--config <filename> Use the given configuration file to determine whether
issues are enabled or disabled. If a project contains
a lint.xml file, then this config file will be used
as a fallback.
If you're using the Eclipse Lint plugin, you can suppress errors directly from the Lint Window. There are three separate ignore levels:
- Always ignore. This completely suppresses the given warning. Use this for warnings you never want flagged.
- Ignore in project. This will ignore this warning in the current project (and any library projects referenced from this project).
- Ignore in file. This will ignore this warning anywhere in the current file, but not in any other files.
- (Ignore warnings within a class, method or even for a specific variable declaration, using annotations or attributes: See this document for more information.)
(Note that support for all 3 in the Lint view is coming in ADT 17; in ADT 16 you can access these from the quick fix menu in the XML editors, and you can access the first two from the Global Options dialog and from the Project Options dialog.)
Project and file specific warnings are written into
lint.xml files into the projects, so command line and build server lint runs will pick these up.