UnusedResources ignore rule is not propagated for referenced resources

551 views
Skip to first unread message

dom...@azimo.com

unread,
Apr 23, 2018, 11:00:05 AM4/23/18
to lint-dev
We define layout library_view.xml to override view from external library. Since lint does not know that, we define ignore rule for that file with 'UnusedResources' category. library_view.xml uses string 'text'. When I run lint, 'text' is marked as apparently unused. It seems that lint only ignores reporting of resources marked with 'UnusedResources', rather than set it's used and propagate it for referenced resources. Is that an expected behaviour, can it be changed? 


Tor Norbye

unread,
Apr 26, 2018, 10:21:49 PM4/26/18
to lint-dev
For resource shrinking, we have several attributes to help you mark resources as used (for example, for resources that are accessed via complex reflection that the resource shrinker analysis can't understand).


And note that the unsused resource detector in lint looks for those same attributes, so once you do they shouldn't show up as unused resources. That's probably better than suppressing the resource warnings.

dom...@azimo.com

unread,
May 18, 2018, 4:42:28 AM5/18/18
to lint-dev
Thank you! I didn't know of 'tools:keep: attributes, now it makes sense and marks referenced resources as used as well.

Pratyush Kshirsagar

unread,
Jul 10, 2018, 12:24:24 PM7/10/18
to lint-dev
@Tor I have a question related to the same topic.
I am working on a custom lint detector to find unused string resources for specific use cases and am trying to use most of the code from UnusedResourceDetector.
What I see is the unused resource detector does not scan for resources that are used in the layout files, preferences xml or any other xml file. At least thats what seems after scanning the code.
I went on to write and run a unit test and it fails to detect the string resource used in the layout xml. But when I run ./gradlew lintDebug on the project it works fine and scans all the xml's to tag the resources as used. I have attached a file with my unit test and the error message at the bottom for your reference. Not sure if there is any plugin to scan and mark the resources.


On Monday, April 23, 2018 at 8:00:05 AM UTC-7, dom...@azimo.com wrote:
UnusedResourceDetectorTest.java
Reply all
Reply to author
Forward
0 new messages