Search code examples
androidgradlemobiledaggerdagger-hilt

Do I need to include dependencies inside the :app module that are provided as @Singleton from another module?


I am currently wondering why I should include a network dependency that normally lives inside my :core module in my :app module. Dagger/Hilt is not capable of resolving my @Singleton OkHttp client which which is defined in :core inside a Hilt Module.

enter image description here

It looks like this:

// :core

@Module
@InstallIn(SingletonComponent::class)
object MyModule {

    ...

    @Provides
    @Singleton
    fun provideOkHttpClient(): OkHttpClient {
        return OkHttpClient.Builder().build()
    }
}
// build.gradle(:core)

dependencies {
    implementation platform(Libs.OkHttp.bom)
    implementation Libs.OkHttp.lib
    implementation Libs.OkHttp.logging
}

Solution

  • It works if you do

    dependencies {
        api platform(Libs.OkHttp.bom)
        api Libs.OkHttp.lib
        api Libs.OkHttp.logging
    }