Я пытаюсь обновить Dagger 2.7 до Dagger 2.21 в приложении для Android. До сих пор это в основном включало добавление новых областей к подкомпонентам, поскольку это реализовано в Dagger 2.8+, но не в Dagger 2.7. Я застрял на несколько часов из-за ошибки, которая, как я надеялся, поможет мне пройти. Ошибка такая:
error: [Dagger/MissingBinding] com.experticity.android.member.model.card.survey.SurveyCampaign cannot be provided without an @Inject constructor or an @Provides-annotated method.
У меня есть метод @Provides
в модуле:
@Module
class SurveyPlayerModule(private val surveyCampaign: SurveyCampaign) {
@Provides
@FragmentScope
fun provideSurveyCampaign(): SurveyCampaign {
return surveyCampaign
}
}
И я предоставляю обзорную кампанию из моего фрагмента:
getComponent().surveyPlayerFragmentComponent(
new SurveyPlayerModule(mSurveyCampaign), new FragmentModule(this));
Класс, который, по-видимому, не может получить опросную кампанию, - это SurveyTracker
, а конструктор выглядит так:
@Inject
public SurveyTracker(UserRepository userRepository, CampaignRepository campaignRepository, SurveyCampaign surveyCampaign) {// Set all of the fields from the constructor parameters}
И да, наш проект представляет собой смесь Kotlin и Java, постепенно продвигаясь к все большему и большему количеству Kotlin.
И остальная часть сообщения об ошибке с краткими названиями пакетов:
SurveyCampaign is injected at SurveyTracker(…, surveyCampaign)
SurveyTracker is provided at SurveyPlayerFragmentComponent.surveyTracker() [ApplicationComponent → SessionComponent → RepositoryComponent → activity.ActivityComponent → activity.SurveyPlayerFragmentComponent]
The following other entry points also depend on it:
SurveyPlayerFragmentComponent.inject(SurveyPlayerViewModel) [ApplicationComponent → SessionComponent → RepositoryComponent → activity.ActivityComponent → activity.SurveyPlayerFragmentComponent]
SurveyPlayerFragmentComponent.inject(SurveyQuestionViewModel) [ApplicationComponent → SessionComponent → RepositoryComponent → activity.ActivityComponent → activity.SurveyPlayerFragmentComponent]
SurveyPlayerFragmentComponent.inject(SurveyCompletedViewModel) [ApplicationComponent → SessionComponent → RepositoryComponent → activity.ActivityComponent → activity.SurveyPlayerFragmentComponent]
Полный, неотредактированный стек ошибок:
ApplicationComponent.java:11: error: [Dagger/MissingBinding] com.experticity.android.member.model.card.survey.SurveyCampaign cannot be provided without an @Inject constructor or an @Provides-annotated method.
public abstract interface ApplicationComponent {
^
com.experticity.android.member.model.card.survey.SurveyCampaign is injected at
com.experticity.android.member.domain.SurveyTracker(…, surveyCampaign)
com.experticity.android.member.domain.SurveyTracker is injected at
com.experticity.android.member.ui.viewmodel.SurveyPlayerViewModel.mSurveyTracker
com.experticity.android.member.ui.viewmodel.SurveyPlayerViewModel is injected at
com.experticity.android.member.injection.component.activity.SurveyPlayerFragmentComponent.inject(com.experticity.android.member.ui.viewmodel.SurveyPlayerViewModel) [com.experticity.android.member.injection.component.ApplicationComponent → com.experticity.android.member.injection.component.SessionComponent → com.experticity.android.member.injection.component.RepositoryComponent → com.experticity.android.member.injection.component.activity.ActivityComponent → com.experticity.android.member.injection.component.activity.SurveyPlayerFragmentComponent]
The following other entry points also depend on it:
com.experticity.android.member.injection.component.activity.SurveyPlayerFragmentComponent.inject(com.experticity.android.member.ui.viewmodel.SurveyQuestionViewModel) [com.experticity.android.member.injection.component.ApplicationComponent → com.experticity.android.member.injection.component.SessionComponent → com.experticity.android.member.injection.component.RepositoryComponent → com.experticity.android.member.injection.component.activity.ActivityComponent → com.experticity.android.member.injection.component.activity.SurveyPlayerFragmentComponent]
com.experticity.android.member.injection.component.activity.SurveyPlayerFragmentComponent.inject(com.experticity.android.member.ui.viewmodel.SurveyCompletedViewModel) [com.experticity.android.member.injection.component.ApplicationComponent → com.experticity.android.member.injection.component.SessionComponent → com.experticity.android.member.injection.component.RepositoryComponent → com.experticity.android.member.injection.component.activity.ActivityComponent → com.experticity.android.member.injection.component.activity.SurveyPlayerFragmentComponent]
А вот и компонент:
@FragmentScope
@Subcomponent(modules = [SurveyPlayerModule::class, FragmentModule::class])
interface SurveyPlayerFragmentComponent {
@ChildFragmentManager
fun childFragmentManager(): FragmentManager
fun surveyTracker(): SurveyTracker
//Fragments
fun inject(fragment: SurveyPlayerFragment)
// ViewModels
fun inject(viewModel: SurveyPlayerViewModel)
fun inject(viewModel: SurveyQuestionViewModel)
fun inject(viewModel: SurveyCompletedViewModel)
// Adapters
fun inject(adapter: SurveyPlayerAdapter)
}