70

How can I find all unused methods and variables of my project in the Android Studio IDE?

Alireza Noorali
  • 3,129
  • 2
  • 33
  • 80
Hamed Ghadirian
  • 6,159
  • 7
  • 48
  • 67
  • 9
    Mr. DownVoter, may I ask you why you down vote this question? – Hamed Ghadirian Nov 12 '15 at 15:14
  • 5
    Not my downvote, but maybe it was someone who read the first words of the title and thought your question falls in an off-topic category: "Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it." I don't think your question is off-topic, but you might want to change the title to "How can I find..." as you wrote in the question body, to prevent misunderstandings. – Fabio says Reinstate Monica Nov 12 '15 at 16:03

3 Answers3

103

In the android studio(or more generally in the Intellij IDEA) you can specify inspection code that you want to analyze from Analyze->Inspect Code... and then define the scope of your code. You can see the result for my code in the below picture:

enter image description here

In Declaration redundancy you can see that "someMethod" is declared unused. Also, in Probable bugs you can find variable i is never used.

Håvard Geithus
  • 5,544
  • 7
  • 36
  • 51
Hamed Ghadirian
  • 6,159
  • 7
  • 48
  • 67
5

You can also install the QAPlug via File -> Settings -> Plugins -> Browse Repositories -> QAPlug.

For Mac:

Android Studio -> Preferences... -> Plugins -> Browse Repositories -> QAPlug.

In QAPlug is PMD, FindBugs, Checkstyle and Hammurapi integrated. These tools are very nice to find dead code, bugs, increase performance and make the code more readable. I highly recommend those tools if you work for a bigger project.

Alireza Noorali
  • 3,129
  • 2
  • 33
  • 80
Erythrozyt
  • 802
  • 6
  • 21
5

Nowadays its in Analyze->Inspect Code... and then you need to go to Kotlin | Redundant contructs | Unused symbol

enter image description here

Jacob Nordfalk
  • 3,533
  • 1
  • 21
  • 21