Android Studio Find Unused Classes



In Android Studio we need to install Gherkin plugin. This plugin provides Gherkin language support. Gherkin is the language that Cucumber uses to define test cases (test scenarios).

The Android Studio has an option where you can browse the most recently opened files on the go. Just press CTRL + E for windows and Command + E for mac and a list of recently opened files will popup. Questions: There is an inspection “Unused declaration” which can find all unused code in Intellij Idea. (see this question) But I want to find all unused classes, not methods, variables etc. (it is difficult to find only classes in 3000 result list). How I can do that? Answers: Press Ctrl+Shift+A Enter “unused declar”.

There is an inspection “Unused declaration” which can find all unused code in Intellij Idea. (see this question)
But I want to find all unused classes, not methods, variables etc. Only classes. (it is difficult to find only classes in 3000 result list). How I can do that?

Answers:
  • Press Ctrl+Shift+A
  • Enter “unused declar”
  • Click double on “Unused declaration”

Settings will pop up

Android studio find unused classes for beginners
  • Click on Java/Declaration redundancy/Unused declaration
  • on the right bottom select “On the fly editor settings”
  • untick check fields, …, check parameters. Only Check Classes should be ticked.
  • Press OK

Seetings closes

  • On menu bar click on Analyze / Run Inspection by Name (or Ctrl+Alt+Shift+I)
  • Insert text “Unused decla”
  • Select “Unused declaration Java|Declaration redundancy”

Search starts

  • Check the job state on bottom of Idea, when finnished: enjoy the results and the greatness feeling of cleaning the messed code. 🙂
Unused

Android Studio Find Unused Classes For Beginners

Answers:
AndroidAndroid Studio Find Unused Classes

I don’t think this is doable. I suspect this feature is intentionally left out of IDEs because it can’t be used safely the way that other “remove unused XXX” refactorings can.

The unused declarations IDEA (and AFAIK, NetBeans) looks for are for private members and local variables: things that are not accessible, even dynamically, from outside that class or scope. (Well, at least without doing things with Reflection or JVM hacking that you’re not supposed to.) No matter what outside code does with your library, it won’t cause those things to be used, because their scope is limited and the IDE can see all of it. The compiler can determine this by looking at just your code.

For classes, even if they don’t have public access, they can be referenced dynamically with Class.forName(), and this actually happens in live code. So even if they’re not apparently used within the code of your project, they might be used depending on what you or external code using your library runs. So the IDE can’t guarantee that removing those classes won’t change externally observable behavior.

Which is why I think IDEA just doesn’t provide this behavior: it might give users false expectations of safety, and removing them is not a safe refactoring.

Answers:

Maybe you should look into the Unused Symbol inspection with the following settings:

Answers:

I am not sure if this will answer your question but I used a tool in past as Fortify to run code review rules on the project, that precisely points to the unused imports, dead code, unused classes etc. It is a paid software but I am sure there will be some free plugins/software will be available for same.

Android Studio Find Unused Classes Free

Android Studio Find Unused Classes

Android Studio Find Unused Classes Online

Tags: class, sed