Dagger/MissingBinding 如果没有 @Provides 注释方法,则无法提供存储库
Dagger/MissingBinding Repository cannot be provided without an @Provides-annotated method
我正在尝试使用 Hilt 设置多模块 Android 应用程序,但在设置所有内容后我收到以下错误:
D:\Projetos\historico-de-notificacoes\app\build\generated\source\kapt\debug\br\com\firstsoft\historiconotificacoes\src\NotificationHistoryApplication_HiltComponents.java:124: error: [Dagger/MissingBinding] br.com.firstsoft.historiconotificacoes.domain.src.repository.NotificationRepository cannot be provided without an @Provides-annotated method.
public abstract static class SingletonC implements NotificationHistoryApplication_GeneratedInjector,
^
br.com.firstsoft.historiconotificacoes.domain.src.repository.NotificationRepository is injected at
br.com.firstsoft.historiconotificacoes.domain.src.usecase.notification.GetRecentNotificationsUseCaseImpl(notificationRepository)
br.com.firstsoft.historiconotificacoes.domain.src.usecase.notification.GetRecentNotificationsUseCaseImpl is injected at
br.com.firstsoft.historiconotificacoes.domain.src.usecase.UseCaseModule.bindsGetRecentNotificationsUseCase(arg0)
br.com.firstsoft.historiconotificacoes.domain.src.usecase.notification.GetRecentNotificationsUseCase is injected at
br.com.firstsoft.historiconotificacoes.src.notifications.recent.RecentViewModel(getRecentNotificationsUseCase)
br.com.firstsoft.historiconotificacoes.src.notifications.recent.RecentViewModel is injected at
br.com.firstsoft.historiconotificacoes.src.notifications.recent.RecentViewModel_HiltModules.BindsModule.binds(vm)
@dagger.hilt.android.internal.lifecycle.HiltViewModelMap java.util.Map<java.lang.String,javax.inject.Provider<androidx.lifecycle.ViewModel>> is requested at
dagger.hilt.android.internal.lifecycle.HiltViewModelFactory.ViewModelFactoriesEntryPoint.getHiltViewModelMap() [br.com.firstsoft.historiconotificacoes.src.NotificationHistoryApplication_HiltComponents.SingletonC ? br.com.firstsoft.historiconotificacoes.src.NotificationHistoryApplication_HiltComponents.ActivityRetainedC ? br.com.firstsoft.historiconotificacoes.src.NotificationHistoryApplication_HiltComponents.ViewModelC]
我的代码设置如下:
:domain
plugins {
id("com.android.library")
id("kotlin-android")
id("kotlin-kapt")
id("dagger.hilt.android.plugin")
}
dependencies {
implementation(Libs.Kotlin.stdLib)
implementation(Libs.Coroutines.core)
implementation(Libs.Paging.runtime)
implementation(Libs.Hilt.core)
kapt(Libs.Hilt.compiler)
}
:data
plugins {
id("com.android.library")
id("kotlin-android")
id("kotlin-kapt")
id("dagger.hilt.android.plugin")
}
dependencies {
implementation(project(":domain"))
implementation(Libs.Kotlin.stdLib)
implementation(Libs.Room.runtime)
implementation(Libs.Room.ktx)
kapt(Libs.Room.compiler)
implementation(Libs.Paging.runtime)
implementation(Libs.Hilt.core)
kapt(Libs.Hilt.compiler)
implementation(Libs.Android.annotation)
implementation(Libs.Util.gson)
}
:app
plugins {
id("com.android.application")
id("kotlin-android")
id("kotlin-kapt")
id("dagger.hilt.android.plugin")
}
dependencies {
implementation(project(":domain"))
implementation(Libs.Kotlin.stdLib)
...
implementation(Libs.Hilt.core)
kapt(Libs.Hilt.compiler)
}
里面 :domain
我有:
interface NotificationRepository {}
里面 :data
我有:
class NotificationRepositoryImpl @Inject constructor(
private val notificationDao: NotificationDao
) : NotificationRepository
@Module
@InstallIn(SingletonComponent::class)
abstract class RepositoryModule {
@Binds
abstract fun bindsNotificationRepository(impl: NotificationRepositoryImpl): NotificationRepository
}
我不知道哪里搞砸了,但这不应该有用吗?如果不是,我做错了什么?
看了这个问题的一些例子和评论之后。我只是通过将 data 模块和 domain 模块实现到我的 app 模块中来解决这个问题:)
但这不是我想的。因此,只需在 app 模块中实现模块,在构建 gradle 文件中的模块应用程序中添加此行
implementation project(":data")
例如,如果您的应用程序中有 3 个模块应用程序、域和数据,您应该在应用程序 build.gradle 文件中实现所有模块。
这里的技巧是在 :app
.
中实现 :data
在我们只有这 3 个模块的特定场景中,:app
、:data
和 :domain
,必须有一个模块聚合其他模块,就是这种情况是 :app
.
我正在尝试使用 Hilt 设置多模块 Android 应用程序,但在设置所有内容后我收到以下错误:
D:\Projetos\historico-de-notificacoes\app\build\generated\source\kapt\debug\br\com\firstsoft\historiconotificacoes\src\NotificationHistoryApplication_HiltComponents.java:124: error: [Dagger/MissingBinding] br.com.firstsoft.historiconotificacoes.domain.src.repository.NotificationRepository cannot be provided without an @Provides-annotated method.
public abstract static class SingletonC implements NotificationHistoryApplication_GeneratedInjector,
^
br.com.firstsoft.historiconotificacoes.domain.src.repository.NotificationRepository is injected at
br.com.firstsoft.historiconotificacoes.domain.src.usecase.notification.GetRecentNotificationsUseCaseImpl(notificationRepository)
br.com.firstsoft.historiconotificacoes.domain.src.usecase.notification.GetRecentNotificationsUseCaseImpl is injected at
br.com.firstsoft.historiconotificacoes.domain.src.usecase.UseCaseModule.bindsGetRecentNotificationsUseCase(arg0)
br.com.firstsoft.historiconotificacoes.domain.src.usecase.notification.GetRecentNotificationsUseCase is injected at
br.com.firstsoft.historiconotificacoes.src.notifications.recent.RecentViewModel(getRecentNotificationsUseCase)
br.com.firstsoft.historiconotificacoes.src.notifications.recent.RecentViewModel is injected at
br.com.firstsoft.historiconotificacoes.src.notifications.recent.RecentViewModel_HiltModules.BindsModule.binds(vm)
@dagger.hilt.android.internal.lifecycle.HiltViewModelMap java.util.Map<java.lang.String,javax.inject.Provider<androidx.lifecycle.ViewModel>> is requested at
dagger.hilt.android.internal.lifecycle.HiltViewModelFactory.ViewModelFactoriesEntryPoint.getHiltViewModelMap() [br.com.firstsoft.historiconotificacoes.src.NotificationHistoryApplication_HiltComponents.SingletonC ? br.com.firstsoft.historiconotificacoes.src.NotificationHistoryApplication_HiltComponents.ActivityRetainedC ? br.com.firstsoft.historiconotificacoes.src.NotificationHistoryApplication_HiltComponents.ViewModelC]
我的代码设置如下:
:domain
plugins {
id("com.android.library")
id("kotlin-android")
id("kotlin-kapt")
id("dagger.hilt.android.plugin")
}
dependencies {
implementation(Libs.Kotlin.stdLib)
implementation(Libs.Coroutines.core)
implementation(Libs.Paging.runtime)
implementation(Libs.Hilt.core)
kapt(Libs.Hilt.compiler)
}
:data
plugins {
id("com.android.library")
id("kotlin-android")
id("kotlin-kapt")
id("dagger.hilt.android.plugin")
}
dependencies {
implementation(project(":domain"))
implementation(Libs.Kotlin.stdLib)
implementation(Libs.Room.runtime)
implementation(Libs.Room.ktx)
kapt(Libs.Room.compiler)
implementation(Libs.Paging.runtime)
implementation(Libs.Hilt.core)
kapt(Libs.Hilt.compiler)
implementation(Libs.Android.annotation)
implementation(Libs.Util.gson)
}
:app
plugins {
id("com.android.application")
id("kotlin-android")
id("kotlin-kapt")
id("dagger.hilt.android.plugin")
}
dependencies {
implementation(project(":domain"))
implementation(Libs.Kotlin.stdLib)
...
implementation(Libs.Hilt.core)
kapt(Libs.Hilt.compiler)
}
里面 :domain
我有:
interface NotificationRepository {}
里面 :data
我有:
class NotificationRepositoryImpl @Inject constructor(
private val notificationDao: NotificationDao
) : NotificationRepository
@Module
@InstallIn(SingletonComponent::class)
abstract class RepositoryModule {
@Binds
abstract fun bindsNotificationRepository(impl: NotificationRepositoryImpl): NotificationRepository
}
我不知道哪里搞砸了,但这不应该有用吗?如果不是,我做错了什么?
看了这个问题的一些例子和评论之后。我只是通过将 data 模块和 domain 模块实现到我的 app 模块中来解决这个问题:)
但这不是我想的。因此,只需在 app 模块中实现模块,在构建 gradle 文件中的模块应用程序中添加此行
implementation project(":data")
例如,如果您的应用程序中有 3 个模块应用程序、域和数据,您应该在应用程序 build.gradle 文件中实现所有模块。
这里的技巧是在 :app
.
:data
在我们只有这 3 个模块的特定场景中,:app
、:data
和 :domain
,必须有一个模块聚合其他模块,就是这种情况是 :app
.