Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/203.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Can';t find Dagger2 module@包含在子组件中时提供带注释的方法_Android_Dagger 2 - Fatal编程技术网

Android Can';t find Dagger2 module@包含在子组件中时提供带注释的方法

Android Can';t find Dagger2 module@包含在子组件中时提供带注释的方法,android,dagger-2,Android,Dagger 2,我的应用程序有一个库(核心库),我们将其作为项目中的一个模块进行维护,并将其作为渐变依赖项包括在内,如下所示: 格雷德尔先生 dependencies { api project(':core') } 我正试图将这个核心库集成为Dagger子组件,就像在RW上显示的那样 我面临的问题是,无法找到CoreModule中所有的@提供带注释的方法,当深入到已编译的DaggerAppComponent生成的文件时,相应的提供方法丢失了,即使它们应该被正确注释。你们知道我做错了吗 这是我收到的错

我的应用程序有一个库(核心库),我们将其作为项目中的一个模块进行维护,并将其作为渐变依赖项包括在内,如下所示:

格雷德尔先生

dependencies {
    api project(':core')
}
我正试图将这个核心库集成为Dagger子组件,就像在RW上显示的那样

我面临的问题是,无法找到CoreModule中所有的@提供带注释的方法,当深入到已编译的DaggerAppComponent生成的文件时,相应的提供方法丢失了,即使它们应该被正确注释。你们知道我做错了吗

这是我收到的错误消息。CoreSettings被注释为@Provides方法,但仍然找不到

android/di/AppComponent.java:12: error: [Dagger/MissingBinding] com.core.util.CoreSettings cannot be provided without an @Inject constructor or an @Provides-annotated method.
    public abstract interface AppComponent {
                    ^
          com.core.util.CoreSettings is injected at com.base.BaseVideoPlayerActivity.coreSettings
      com.base.BaseVideoPlayerActivity is injected at
          com.di.AppComponent.inject(com.base.BaseVideoPlayerActivity)
  It is also requested at:
      com.base.BaseVideoPlayerActivity.coreSettings
  The following other entry points also depend on it:
      com.di.AppComponent.inject(com.ui.LiveVideoActivity)
DaggerAppComponent.java(此处缺少在CoreModule中声明的CoreSettings的提供程序方法)

我尝试过很多不同的方法,比如直接在AppComponent中包含CoreModule,它工作得非常好,但当它是子组件的一部分时就不行了

以下是文件分类:

AppComponent.kt

@ApplicationScope
@Component(modules = [UtilsModule::class, CoreLibraryModule::class])
interface AppComponent {

    @Component.Factory
    interface Factory {
        fun create(modules: UtilsModule): AppComponent
    }
    
    fun coreComponentFactory(): CoreComponent.Factory

    /**
     * Classes that can be injected by this Component
     */
    fun inject(app: AppApplication)
}
/**
 * Subcomponent that provides injection mechanism to Core Library classes
 */
@Subcomponent(modules = [CoreModule::class])
interface CoreComponent {

    @Subcomponent.Factory
    interface Factory {
        fun create(module: CoreModule): CoreComponent
    }

    /**
     * Classes that can be injected by this Component
     */
    fun inject(app: FeedDownloadService)
}
UtilsModule.kt

@Module
class UtilsModule(private val ctx: Context) {

    @ApplicationScope
    @Provides
    fun provideApplicationContext(): Context = ctx
}
CoreLibraryModule.kt

/**
 * Wrapper module for the CoreComponent to be included in the AppComponent
 */
@Module(subcomponents = [CoreComponent::class, SplashComponent::class])
object CoreLibraryModule
CoreComponentProvider.kt

/**
 * Interface that provides a CoreComponent that Core Library classes can use for injection.
 * This interface must be implemented by the Application subclass.
 */
interface CoreComponentProvider {
    fun getCoreComponentFactory(): CoreComponent.Factory
}
CoreComponent.kt

@ApplicationScope
@Component(modules = [UtilsModule::class, CoreLibraryModule::class])
interface AppComponent {

    @Component.Factory
    interface Factory {
        fun create(modules: UtilsModule): AppComponent
    }
    
    fun coreComponentFactory(): CoreComponent.Factory

    /**
     * Classes that can be injected by this Component
     */
    fun inject(app: AppApplication)
}
/**
 * Subcomponent that provides injection mechanism to Core Library classes
 */
@Subcomponent(modules = [CoreModule::class])
interface CoreComponent {

    @Subcomponent.Factory
    interface Factory {
        fun create(module: CoreModule): CoreComponent
    }

    /**
     * Classes that can be injected by this Component
     */
    fun inject(app: FeedDownloadService)
}
CoreModule.kt

@Module
class CoreModule {

    @ApplicationScope
    @Provides
    fun provideCoreSettings(): CoreSettings = CoreSettings.getInstance()
}
BaseVideoPlayerActivity.kt

class BaseVideoPlayerActivity: Activity {

    @Inject
    lateinit var coreSettings: CoreSettings

    override fun onCreate(savedInstanceState: Bundle?) {
        // Inject dependencies via Dagger here.
        (application as AppApplication).appComponent.inject(this)
    }
}