使用@Subcomponent Android Dagger 2.x无法正常工作

时间:2019-04-10 14:40:17

标签: android kotlin dagger-2 dagger

在尝试使用Dagger的子组件时遇到问题。当我尝试构建此文件时,出现此错误。

  

@ Subcomponent.Builder的setter方法必须返回void,构建器或构建器的超类型。继承的方法:create(T)。

有人知道我在做什么错吗?

谢谢。

@FragmentScope
@Subcomponent(modules = [OnBoardingWelcomeFragmentModule::class])
interface OnBoardingWelcomeFragmentComponent: AndroidInjector<OnBoardingWelcomeFragment> {

  @Subcomponent.Builder
  interface Builder: AndroidInjector.Factory<OnBoardingWelcomeFragment>


}

@Module
open class OnBoardingWelcomeFragmentModule {

  @Provides
  @FragmentScope
  fun provideUI() = OnBoardingWelcomeFragmentUi()

  @Provides
  @ViewModelForDagger
  fun providesViewModelForDagger(sharedPrefsStorage: SharedPrefsStorage): OnboardingViewModel =
    OnboardingViewModel(sharedPrefsStorage)

  @Provides
  fun providesViewModelFactory(@ViewModelForDagger
                               viewModel: Lazy<OnboardingViewModel>): ViewModelFactory<OnboardingViewModel> =
    ViewModelFactory(viewModel)

}

1 个答案:

答案 0 :(得分:2)

您应该将218646.m4f 218647.m4f 218648.m4f 218649.m4f 218650.m4f 218651.m4f 218652.m4f 218653.m4f 218654.m4f 218655.m4f 218656.m4f 218657.m4f 218658.m4f 218659.m4f 218660.m4f 218661.m4f 218662.m4f 218663.m4f 218664.m4f 218665.m4f 218666.m4f 218667.m4f 218668.m4f 218669.m4f 218670.m4f 218671.m4f 218672.m4f 218673.m4f 218674.m4f init.mp4 切换为cat init.mp4 > source.mp4 cat segment-1.m4f >> source.mp4 cat segment-2.m4f >> source.mp4 ... 来实现AndroidInjector.Factory

AndroidInjector.Builder

AndroidInjector.Factory界面为abstract class Builder: AndroidInjector.Builder<OnBoardingWelcomeFragment> 添加了一种方法,您必须自己实现该方法,因为Dagger不知道如何—因此出现错误。