lint检查忽略通过getIdentifier引用的资源

467 阅读1分钟

1、新建一个Module,将需要通过getIdentifier方法引用的资源放置在此Module中

2.在Module下的build.gradle中添加如下配置:

android {
    // 省略部分配置代码
    lintOptions {
        lintConfig file('lint.xml')
    }
}

3.在build.gradle同级目录下新建lint.xml,并增加类似如下配置:

<?xml version="1.0" encoding="UTF-8"?>
<lint>

    <issue id="UnusedResources" severity="ignore">
        <ignore path="res/drawable-xxhdpi" />
    </issue>
</lint>

其中path可输入对应的目录,例如若想忽略字符串则可增加 <ignore path="res/values/string.xml"/> 配置

通过以上配置,在进行lint检查去除无效资源时,通过getIdentifier方法获取的资源便不会提示为无效资源