我是否需要在 :app 模块中包含从另一个模块作为 @Singleton 提供的依赖项?
Do I need to include dependencies inside the :app module that are provided as @Singleton from another module?
我目前想知道为什么我应该在我的 :app 模块中包含通常存在于我的 :core 模块中的网络依赖项。 Dagger/Hilt 无法解析我的 @Singleton OkHttp 客户端,它在 Hilt 模块的 :core 中定义。
看起来像这样:
// :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
}
如果你这样做就有效
dependencies {
api platform(Libs.OkHttp.bom)
api Libs.OkHttp.lib
api Libs.OkHttp.logging
}
我目前想知道为什么我应该在我的 :app 模块中包含通常存在于我的 :core 模块中的网络依赖项。 Dagger/Hilt 无法解析我的 @Singleton OkHttp 客户端,它在 Hilt 模块的 :core 中定义。
看起来像这样:
// :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
}
如果你这样做就有效
dependencies {
api platform(Libs.OkHttp.bom)
api Libs.OkHttp.lib
api Libs.OkHttp.logging
}