我在项目中使用匕首起诉,但出现以下错误:
error: [Dagger/MapKeys] The same map key is bound more than once for java.util.Map<java.lang.Class<?>,javax.inject.Provider<dagger.android.AndroidInjector.Factory<?>>>
public abstract interface AppComponent extends dagger.android.AndroidInjector<dagger.android.DaggerApplication> {
^
@Binds @dagger.multibindings.IntoMap @dagger.multibindings.ClassKey(com.Courses.CoursesActivity.class) dagger.android.AndroidInjector.Factory<?> com.Courses.module.CoursesActivityProvider_CoursesActivity.bindAndroidInjectorFactory(com.Courses.module.CoursesActivityProvider_CoursesActivity.CoursesActivitySubcomponent.Factory)
@Binds @dagger.multibindings.IntoMap @dagger.multibindings.ClassKey(com.Courses.CoursesActivity.class) dagger.android.AndroidInjector.Factory<?> com.di.ActivityBuilder_BindCoursesActivity.bindAndroidInjectorFactory(com.di.ActivityBuilder_BindCoursesActivity.CoursesActivitySubcomponent.Factory)
java.util.Map<java.lang.Class<?>,javax.inject.Provider<dagger.android.AndroidInjector.Factory<?>>> is injected at
dagger.android.DispatchingAndroidInjector(injectorFactoriesWithClassKeys, …)
dagger.android.DispatchingAndroidInjector<java.lang.Object> is injected at
dagger.android.support.DaggerAppCompatActivity.androidInjector
com.Courses.CoursesActivity is injected at
dagger.android.AndroidInjector.inject(T) [com.di.AppComponent → com.di.ActivityBuilder_BindCoursesActivity.CoursesActivitySubcomponent]
The following other entry points also depend on it:
dagger.android.AndroidInjector.inject(T) [com.di.AppComponent → com.di.ActivityBuilder_BindCoursesActivity.CoursesActivitySubcomponent → com.Courses.module.CoursesActivityProvider_CoursesActivity.CoursesActivitySubcomponent]
这里是AppScoped
:
@Scope
@kotlin.annotation.Retention(AnnotationRetention.RUNTIME)
annotation class AppScoped
还有CoursesActivityScope
:
@Scope
@kotlin.annotation.Retention(AnnotationRetention.RUNTIME)
annotation class CoursesActivityScope
还有ActivityBuilder
:
@Module
abstract class ActivityBuilder {
@ContributesAndroidInjector(modules = [CoursesActivityProvider::class])
abstract fun bindCoursesActivity(): CoursesActivity?
}
还有AppComponent
:
@AppScoped
@Component(modules = [
AndroidSupportInjectionModule::class,
AppModule::class,
ActivityBuilder::class])
interface AppComponent : AndroidInjector<DaggerApplication?> {
fun inject(app: App?)
override fun inject(instance: DaggerApplication?)
@Component.Builder
interface Builder {
@BindsInstance
fun application(application: Application?): Builder?
fun build(): AppComponent?
}
}
还有AppModule
:
@Module
abstract class AppModule {
@Binds
abstract fun provideContext(application: Application?): Context?
}
还有App
:
import dagger.android.support.DaggerApplication;
@AppScoped
class App : DaggerApplication() {
override fun applicationInjector(): AppComponent? {
val appComponent = DaggerAppComponent
.builder()
.application(this)
?.build()
appComponent!!.inject(this)
return appComponent
}
}
这是我的Activity
:
@CoursesActivityScope
class CoursesActivity : DaggerAppCompatActivity(){
......
}
但是让我克服错误。
答案 0 :(得分:0)
我将此class
编辑为:
@Module
abstract class ActivityBuilder {
@CoursesActivityScope
@ContributesAndroidInjector(modules = [CoursesActivityModule::class])
abstract fun bindCoursesActivity(): CoursesActivity?
}