Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect unused resources in Xamarin.Android?

Is there a way in Xamarin.Android to detect unused resources? I'd like to specifically detect drawables that I'm no longer using.

I believe that the Resource.designer.cs and the R.java in \obj could be used to create a program that does this I'm just not sure if there is a way already out there? In Android you can normally use Lint to detect this but it appears to detect everything as unused when pointed at a Xamarin.Android project.

like image 984
egfconnor Avatar asked Jun 18 '14 14:06

egfconnor


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.


2 Answers

You can use the lint tool with Xamarin.Android projects, we have a new xbuild/msbuild property AndroidLintEnabled with this property set to true either by adding it to a command line

/p:AndroidLintEnabled=true

or by adding it to the .csproj

<AndroidLintEnabled>true</AndroidLintEnabled >

the android lint tool will be run and the warnings/errors will be output as normal xbuild/msbuild errors and warnings.

like image 184
Prashant Cholachagudda Avatar answered Oct 15 '22 18:10

Prashant Cholachagudda


The only way I know, is human work.

I think that the better, way is exclude all drawable files, compile, check drawable errors, add one by one and the drawables don't be added you will delete.

Yeah, I know is a lot of work, but there any util that helps.

Other way, is search in all your Project every drawable file name. If the only place you get this file is Resources, delete it.

Sorry, don't help you with another solution :(

like image 28
jmmontero Avatar answered Oct 15 '22 18:10

jmmontero