I just noticed android studio got a new feature that allows us to click a button and find the consumers for a particular @Provides
functions, my question is, is there any way to to kind of go through all the @Module
classes and find the ones that are not used anywhere in the project in 1 iteration using a script or a tool?
Asked
Active
Viewed 467 times
4

Bhargav
- 8,118
- 6
- 40
- 63
-
Does this answer your question? [How to use IntelliJ IDEA to find all unused code?](https://stackoverflow.com/questions/6587729/how-to-use-intellij-idea-to-find-all-unused-code) – denvercoder9 Nov 09 '20 at 16:03
1 Answers
1
Full code:
@Module
@InstallIn(ApplicationComponent::class)
object RemoteDataSourceModule {
@Singleton
@Provides
fun provideNetworkApi(): NetworkApi = NetworkApi.getInstance()
@Singleton
@Provides
fun provideFcmApi(): FcmApi = FcmApi.getInstance()
}
Pictures of it in Android Studio
My version of Android Studio is 4.1
In the picture I attached of my RemoteDataSourceModule
in Android Studio you can see the left sidebar. [The one between line numbers and the code itself]
On that sidebar, you can that icon. [Not sure what it looks like] This is the icon for dependencies.
If you hover over that icon you will where is the particular dependency is provided. [See example in my picture]
This way you can track all the places where said dependency is injected. Once no places are detected, that icon will disappear.
Edit: I just found a link to this part of Android Studio release notes: Refer here for more information: https://developer.android.com/studio/releases#dagger-navigation

Vitaliy-T
- 733
- 6
- 23
-
3you gave me something useful with "no icon displayed if no uses" part (gave you an upvote for that one and the nice clear suggestion), but apart from that what I am actually looking for here is to get ALL the unused provides function names at once, manually going through each of them is very painful, there are 100s of provides functions in my project – Bhargav Nov 06 '20 at 04:07