This page is obsolete. Redirecting to https://developer.android.com/studio/write/lint.html#config 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. In SourceYou can suppress lint issues directly in the source code. This has the advantage that you filter only this specific occurrence of the lint issue (that you've presumably manually verified), not all occurrences of a particular issue type, or all occurrences in a file.With AnnotationsIn .java files, you can suppress issues with the @SuppressLint annotations. You supply the lint issue id as the argument to the annotations.For example @SuppressLint("NewApi") public void onGlobalLayout() { .... You can also suppress more than one issue using a comma separated list: @SuppressLint({"NewApi","StringFormatInvalid"}) In both Android Studio and Eclipse you can easily suppress lint issues directly without having to write the annotation yourself. Just invoke the quickfix for the warning, and one of the options will be to ignore the issue with an annotation; this will annotate either the local declaration, or the method, or the class, or the field, depending on the location of the error. (Some screenshots of this in action in Eclipse is shown here.) In .xml files, you suppress issues with the special tools:ignore attribute instead.<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"> .... <LinearLayout tools:ignore="MergeRootFrame" ... all " to indicate all issues.In Source: With CommentsIn recent versions of lint, you can also use a special line comment on the line above the error to suppress a warning. In .java and .gradle files, use a comment line this (where again the issue id can be a comma separated list of id's). You can prefix the id with "AndroidLint", which is allowed for consistency with the way IntelliJ disables inspections in comments.) //noinspection AndroidLintSdCardPath String path = "/sdcard/legacy.txt"; <!--suppress AndroidLintHardcodedText --> (Again, you can supply a comma separated list of issue ids instead of a single id.) In Build File: With Gradle ConfigurationIn Gradle files, you can specify a lintOptions configuration where you can disable id's, enable id's, as well as change the severity of issue id's (including to "ignore" to disable them). android { lintOptions { disable 'TypographyFractions','TypographyQuotes' ... } } From Command LineThe lint command has three commands for controlling which checks are performed: --enable , --disable and --check (see the overview document for more details on these flags). However, these must be specified each time you run lint. This is similar to the lintOptions for Gradle above.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. Gradle, Android Studio and Eclipse will also use this configuration file if present. 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"?> <lint> <!-- Disable the given check in this project --> <issue id="IconMissingDensityFolder" severity="ignore" /> <!-- Ignore the ObsoleteLayoutParam issue in the given files --> <issue id="ObsoleteLayoutParam"> <ignore path="res/layout/activation.xml" /> <ignore path="res/layout-xlarge/activation.xml" /> </issue>
<!-- Ignore the UselessLeaf issue in the given file --> <issue id="UselessLeaf"> <ignore path="res/layout/main.xml" /> </issue> <!-- Change the severity of hardcoded strings to "error" --> <issue id="HardcodedText" severity="error" /> </lint> In recent versions of lint (Gradle plugin 0.9+, SDK Tools 27+, Android Studio 0.5+) you can use a globbing pattern for the path: <issue id="ObsoleteLayoutParam"> <ignore path="res/**/activation.xml" /> You can also specify a full regular expression, by using a regexp attribute instead of path : <ignore regexp="res/.*/activation.xml" /> You can also use " Finally, as of Android Studio 0.9 and Gradle plugin 0.14.+ you can use a regular expression to match the error message as well: <ignore regexp="Invalid package reference in library; not included in Android: java.* Referenced from " /> Issue Id'sThe issue identifiers used to suppress issues as shown above (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] lint --show command (for full details) or lint --list (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 LinearLayouts "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 flag:--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. From Android Studio
|
Tips > Android Lint >