65

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

Alireza Noorali
  • 3,777
  • 2
  • 26
  • 71
Hamed Ghadirian
  • 5,881
  • 5
  • 43
  • 65
  • 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

100

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,324
  • 6
  • 32
  • 49
Hamed Ghadirian
  • 5,881
  • 5
  • 43
  • 65
6

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,777
  • 2
  • 26
  • 71
Erythrozyt
  • 804
  • 6
  • 20
1

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,443
  • 1
  • 19
  • 21