How to clean Android project?

I used the source code of the Android application, which we created in the past as the basis for another application (many functions are similar, but about 1/3 of the functionality of the original application is removed).

I started by copying the source tree and importing the new project into the Eclipse workspace. After that, I deleted some layouts and files with the ability to draw, and several .java files - those that are clearly not needed in the new application.

Finally, I compiled and tested a new application. Now I would like to do a more thorough cleaning of the project, removing almost everything that is not used.

What is the best way to find all the XML and image files, Java files, strings and color resources that are not used in the new application? “Not used”, I mean that they are not referenced by any of the executable code of the application (starting from the main action, they go to all other files specified in it, files transferred from these files, etc. )

The project contains hundreds of Drawables (many of them have versions in HDPI, MDPI and LDPI), about a hundred or so layouts, and about a thousand Java files in a dozen different packages. Therefore, checking them one by one is not an option.

Edit March 2012: The latest version of the Android SDK lint tool pretty well identifies unused resources. The problem is filtering messages about unused resources from hundreds of other messages that I received. When I launched the link to my medium-sized project, I had over 3,000 warnings, most of which I intend to do nothing, because lint cannot analyze what I am doing in the code with my XML layouts.

+7
source share
2 answers

Check out http://code.google.com/p/android-unused-resources/

It works with open source code, is actively developed and created / supported by an excellent developer.

+2
source

AFAIK, there is no automated tool for this. I also looked for a way to detect unused resources and came to the conclusion that there is no tool for this. In addition, you are talking about unused Java files, which, it seems to me, are even more difficult to perform (it is difficult to determine what actions / services / receivers / providers are actually used, etc.).

I suggest grepping through the project tree for resources and classes that you suspect are no longer used and delete those that are not displayed anywhere.

0
source

All Articles