【问题标题】:Do I need to include dependencies inside the :app module that are provided as @Singleton from another module?我是否需要在 :app 模块中包含从另一个模块作为@Singleton 提供的依赖项?
【发布时间】:2021-03-20 17:12:45
【问题描述】:

我目前想知道为什么我应该在我的 :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
}

【问题讨论】:

    标签: android gradle mobile dagger dagger-hilt


    【解决方案1】:

    如果你这样做,它会起作用

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

    【讨论】:

      猜你喜欢
      • 2018-03-13
      • 2012-04-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-22
      • 1970-01-01
      • 2021-11-16
      相关资源
      最近更新 更多