Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clean up an Android project?

I used source code of an android app that we created in the past as a basis for another app (a lot of the functionality is similar, however about 1/3 of the functionality of the original app is removed).

I started by copying the source tree and importing a new project into Eclipse workspace. After that, I deleted some layout and drawable files and a few .java files - the ones that obviously are not needed in a new app.

Finally, I have compiled and tested the new app. Now I would like to do a more thorough cleanup of the project by deleting pretty much everything that's not used.

What is the best way to find all XML and image files, Java files, strings and colour resources that are not used in the new app? By "not used", I mean that they are not referenced from any of the executing application code (starting from main activity, go to all other files referred from it, files referred from those files - and so on).

The project contains hundreds of Drawables (many of them have versions in HDPI, MDPI and LDPI), around a hundred or so layouts and close to 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 android SDK's lint tool identifies unused resources quite well. The issue is to filter the messages about unused resources from hundreds of other messages I got. When I ran link on my medium-sized project, I got over 3,000 warnings from it, most of which I intend to do nothing about, because lint cannot analyse what I do in the code with my XML layouts.

like image 710
Aleks G Avatar asked Oct 06 '11 12:10

Aleks G


People also ask

How do you clean a project?

Manually delete the [project]/. gradle as hidden folder as that one is the main culprit for large cleaned projects sizes. and don't forget to manually delete the [project]/. gradle hidden folder as that one is the main culprit for large cleaned projects sizes.

What happens when you clean a project in Android Studio?

Cleaning an Android project simply deletes the build directory. It removes the . class files that are generated when you compile your project and then recompiles again.

How do you clean and rebuild a project?

On the menu bar, choose Build, and then choose either Build ProjectName or Rebuild ProjectName. Choose Build ProjectName to build only those project components that have changed since the most recent build. Choose Rebuild ProjectName to "clean" the project and then build the project files and all project components.

What is a clean build in android?

Obviously, try to clean your project from android studio : “Build -> Clean Project”. This will clear your build folders. Clear the cache of Android Studio using “File -> Invalidate Caches / Restart” choose “Invalidate and restart option” and close Android Studio.


1 Answers

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

It's open source, in active development, and created/maintained by a great developer.

like image 127
Mike dg Avatar answered Sep 27 '22 02:09

Mike dg