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.
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.
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.
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.
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.
Check out http://code.google.com/p/android-unused-resources/
It's open source, in active development, and created/maintained by a great developer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With