Search code examples
androidxmltranslationlintsuppress

How to suppress lint on specific line/string in resources xml files?


On Android, I would like to suppress lint on a specific string value or specific line on a string.xml or other resources files.

<string name="suppress_lint_string">Suppress this String</string>

<string name="dont_suppress_lint_string">Don\'t Suppress this String</string>

I would like to perform specific lint suppressing on specific strings and specific parts of layouts for examples like missing translations for specific strings that doesn't really matter between languages.


Solution

  • If you want to suppress specific rules in specific strings without suppressing the whole file, you can use annotations.

    strings.xml

    <?xml version="1.0" encoding="utf-8"?>
    <resources>    
    
        <!--suppress MissingTranslation -->
        <string name="suppress_lint_string">ignore my translation</string>
        ...
    
    </resources>
    

    You can substitute MissingTranslation with any other lint rule.

    http://tools.android.com/tips/lint/suppressing-lint-warnings