Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Incorrect Android Lint warning on Unused Resources

After I run Lint in Eclipse, it shows a list of unused resources, mainly drawable. Some of them are incorrect. It is saying that some of the resource are unused, but in fact, it is actually being used in array.xml.

E.g. The resource R.drawable.test appears to be unused

In array.xml,

<string-array name="icon">
        <item>test</item>
</string-array>

Then in my activity, I use following code to retrieve the resource

String[] icon = getResources().getStringArray(icon);
iconRes = getResources().getIdentifier(icon[itemPos], "drawable", this.getPackageName());

I tried to run lint in terminal and it's giving the same result.

like image 913
Darren Avatar asked Apr 24 '14 15:04

Darren


People also ask

How do I delete unused resources in Android?

In Android Studio Menu > Refactor > Remove Unused Resources... Select the resources you want to remove. You can exclude resources you want to keep by right-clicking on the resource item. Use Do Refactor to remove all Resources at once.

How do you stop lint errors?

To suppress a lint warning with a comment, add a //noinspection id comment on the line before the statement with the error. Here we specify a comma separated list of issue id's after the disable command. You can also use warning or error instead of disable to change the severity of issues.

What are lint errors in Android?

The lint tool checks for structural code problems that could affect the quality and performance of your Android application. It is strongly recommended that you correct any errors that lint detects before publishing your application.

How do you check for lint errors?

Module and file-specific preferences Run the lint tool on your module by right-clicking on your module folder or file in the Project View and selecting Analyze > Inspect Code. This displays the lint inspection results with a list of issues that lint detected in your module.


1 Answers

Lint often produces false positives on unused resources.

You can set them to Information or Ignore instead of Warning (Window/Preferences/Android/Lint Error Checking/Performance/UnusedResources).

enter image description here

like image 172
Phantômaxx Avatar answered Oct 29 '22 15:10

Phantômaxx