How can I exclude some unused images from lint in Android Studio using lint.xml?
I have a large number of images in my folder drawable-xhdpi
that show up as unused when I run lint. These files are dynamically referenced at runtime and therefore do not have static links.
I would like to customize my lint.xml
so that these files are excluded from lint. I added XML to the module directory (not the top level project directory, but the module directory) with the required directives, but I still can't get it to ignore.
<?xml version="1.0" encoding="UTF-8"?>
<!--suppress XmlUnboundNsPrefix -->
<lint>
<issue id="AndroidLintUnusedResources">
<ignore path="res/drawable-xhdpi/i0.png" />
</issue>
</lint>
source to share
If you are only linking to images dynamically, and if they are in only one size ( drawable-xhdpi
), it might be a good idea to put them in assets
instead res
.
If not, try installing path="**/res/drawable-xhdpi/i0.png"
.
Also, the id problem that worked for me was id="UnusedResources"
insteadid="AndroidLintUnusedResources"
Don't forget to include the link lint.xml
in build.gradle
:
android {
lintOptions {
lintConfig file('lint.xml')
}
}
In this case, lint.xml
they build.gradle
are placed in the same directory.
source to share