简体   繁体   中英

How can I exclude some unused images from lint in Android Studio using the lint.xml?

I have a large amount of images in my drawable-xhdpi folder that show up as unused when I run lint. These files are referenced dynamically at runtime and, therefore, have no static references.

I'd like to configure my lint.xml so that these files are excluded from lint. I've added an XML at the module directory (not the top-level project directory but the module directory) with the necessary directives but I still can't get lint to ignore them.

<?xml version="1.0" encoding="UTF-8"?>
<!--suppress XmlUnboundNsPrefix -->
<lint>
    <issue id="AndroidLintUnusedResources">
        <ignore path="res/drawable-xhdpi/i0.png" />
    </issue>
</lint>

If you reference the images only dynamically and if they are only in one size ( drawable-xhdpi ), it might be a good idea to put them into assets instead of res .

Otherwise, try setting path="**/res/drawable-xhdpi/i0.png" .

Also, the issue id that worked for me was id="UnusedResources" instead of id="AndroidLintUnusedResources"

Remember to put reference to lint.xml in your build.gradle :

android {
    lintOptions {
        lintConfig file('lint.xml')
    }
}

In this case, lint.xml and build.gradle are placed in the same directory.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM