<AndroidInjector.Factory <? extends android.support.v4.app.Fragment >>> не может быть предоставлен без аннотируемого метода @Provides

Когда я использую AndroidInjector как ниже для non supportLibrary

class MainApplication: DaggerApplication() {
    override fun applicationInjector(): AndroidInjector<MainApplication> {
        return DaggerAppComponent.builder().application(this).build()
    }
}

@Component(modules = [AndroidInjectionModule::class, ActivityBuilder::class])
interface AppComponent: AndroidInjector<MainApplication> {
    @Component.Builder
    interface Builder {
        @BindsInstance
        fun application(application: MainApplication): Builder
        fun build(): AppComponent
    }
}

@Module
abstract class ActivityBuilder {
    @ContributesAndroidInjector(modules = [MainActivityModule::class])
    abstract fun bindMainActivity(): MainActivity
}

class MainActivity : DaggerActivity() {

    @Inject lateinit var info : Info

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        my_text.text = info.text
    }
}

class Info {
    val text = "Hello Dagger Android"
}

@Module
class MainActivityModule {
    @Provides
    fun getInfo() = Info()
}

Все работает хорошо. Однако, когда я перехожу на версию поддержки

class MainApplication: dagger.android.support. DaggerApplication() {
    override fun applicationInjector(): AndroidInjector<MainApplication> {
        return DaggerAppComponent.builder().application(this).build()
    }
}

@Component(modules = [AndroidInjectionModule::class, ActivityBuilder::class])
interface AppComponent: AndroidInjector<MainApplication> {
    @Component.Builder
    interface Builder {
        @BindsInstance
        fun application(application: MainApplication): Builder
        fun build(): AppComponent
    }
}

@Module
abstract class ActivityBuilder {
    @ContributesAndroidInjector(modules = [MainActivityModule::class])
    abstract fun bindMainActivity(): MainActivity
}

class MainActivity : DaggerAppCompatActivity() {

    @Inject lateinit var info : Info

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        my_text.text = info.text
    }
}

class Info {
    val text = "Hello Dagger Android"
}

@Module
class MainActivityModule {
    @Provides
    fun getInfo() = Info()
}

У меня есть эта ошибка. Что вызывает это?

error: [Dagger/MissingBinding] java.util.Map<java.lang.Class<? extends android.support.v4.app.Fragment>,javax.inject.Provider<dagger.android.AndroidInjector.Factory<? extends android.support.v4.app.Fragment>>> cannot be provided without an @Provides-annotated method.
public abstract interface AppComponent extends dagger.android.AndroidInjector<com.elyeproj.demodaggerandroid.MainApplication> {
                ^
  java.util.Map<java.lang.Class<? extends android.support.v4.app.Fragment>,javax.inject.Provider<dagger.android.AndroidInjector.Factory<? extends android.support.v4.app.Fragment>>> is injected at
      dagger.android.DispatchingAndroidInjector(…, boundedInjectorFactoriesWithClassKeys, …)
  dagger.android.DispatchingAndroidInjector<android.support.v4.app.Fragment> is injected at
      dagger.android.support.DaggerApplication.supportFragmentInjector
  com.elyeproj.demodaggerandroid.MainApplication is injected at
      dagger.android.AndroidInjector.inject(T)
  The following other entry points also depend on it:
  dagger.android.AndroidInjector.inject(T) [com.elyeproj.demodaggerandroid.AppComponent → com.elyeproj.demodaggerandroid.ActivityBuilder_BindMainActivity.MainActivitySubcomponent] 

1 ответ

Видимо у меня AndroidSupportInjectionModule вместо AndroidInjectionModuleт.е.

@Component(modules = [AndroidInjectionModule::class, ActivityBuilder::class])

в

@Component(modules = [AndroidSupportInjectionModule::class, ActivityBuilder::class])
Другие вопросы по тегам