I'm trying to apply DaggerApplicationComponent in MVVM architecture by modifying MVP app, Belajar App, but I've just got error of Unresolved reference: DaggerApplicationComponent. Kotlin kapt has been applied and I've tried to rebuild project, but instead I got error from application component: C:\Users\3\AndroidStudioProjects\belajar3 - Copy (3)\app\build\tmp\kapt3\stubs\debug\id\kotlin\belajar\di\component\ApplicationComponent.java:8: error: [Dagger/MissingBinding] retrofit2.Retrofit cannot be provided without an @Inject constructor or an @Provides-annotated method. public abstract interface ApplicationComponent extends dagger.android.AndroidInjector<id.kotlin.belajar.BelajarApp> { ^ retrofit2.Retrofit is injected at id.kotlin.belajar.di.module.HomeModule.providesHomeDatasource(retrofit) id.kotlin.belajar.data.HomeDatasource is injected at id.kotlin.belajar.presentation.HomeViewModel(datasource) id.kotlin.belajar.presentation.HomeViewModel is injected at id.kotlin.belajar.di.module.HomeModule.bindHomeViewModel(viewModel) java.util.Map<java.lang.Class<? extends androidx.lifecycle.ViewModel>,javax.inject.Provider<androidx.lifecycle.ViewModel>> is injected at id.kotlin.belajar.di.factory.ViewModelFactory(viewModels) id.kotlin.belajar.di.factory.ViewModelFactory is injected at id.kotlin.belajar.di.builder.ActivityBuilder.bindViewModelFactory(factory) androidx.lifecycle.ViewModelProvider.Factory is injected at id.kotlin.belajar.presentation.HomeActivity.viewModelFactory id.kotlin.belajar.presentation.HomeActivity is injected at dagger.android.AndroidInjector.inject(id.kotlin.belajar.presentation.HomeActivity) [id.kotlin.belajar.di.component.ApplicationComponent ? id.kotlin.belajar.di.builder.ActivityBuilder_ContributeHomeActivity.HomeActivitySubcomponent]
I need suggestion for this problem. Thank you.
This is the code:
ApplicationComponent:
import dagger.Component
import dagger.android.AndroidInjector
import dagger.android.support.AndroidSupportInjectionModule
import id.kotlin.belajar.BelajarApp
import id.kotlin.belajar.di.builder.ActivityBuilder
import id.kotlin.belajar.di.module.Networkmodule
import javax.inject.Singleton
@Singleton
@Component(modules = [
AndroidSupportInjectionModule::class, Networkmodule::class,
ActivityBuilder::class
])
interface ApplicationComponent : AndroidInjector<BelajarApp>
BelajarApp:
import dagger.android.AndroidInjection.inject
import dagger.android.AndroidInjector
import dagger.android.DaggerApplication
import id.kotlin.belajar.di.component.DaggerApplicationComponent
class BelajarApp : DaggerApplication(){
override fun applicationInjector(): AndroidInjector<out DaggerApplication>? {
return DaggerApplicationComponent.create().apply { inject(this@BelajarApp) }
}
}
My github repo: