Find and remove unused `@Provides` in dagger `@Module` classes

Viewed 278

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?

1 Answers

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

enter image description here

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.

enter image description here

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

Related