I am trying to use the new dagger api for activity injection but I am getting error lateinit property dispatchingAndroidInjector has not been initialized
// AppComponent.kt
@Singleton
@Component(modules = [
AndroidSupportInjectionModule::class,
ActivitiesModule::class
])
interface AppComponent {
fun inject(app: Application)
@Component.Builder
interface Builder {
fun build(): AppComponent
@BindsInstance
fun bindApplication(application: Application): Builder
}
}
Activity Modules file
@Module
abstract class ActivitiesModule {
@ContributesAndroidInjector
abstract fun provideRestaurantMainActivity(): MainActivity
}
In my MainActivity I am calling the injection
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
AndroidInjection.inject(this)
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
}
}
And in my Application
class App : Application(), HasActivityInjector{
@Inject
lateinit var dispatchingAndroidInjector: DispatchingAndroidInjector<Activity>
override fun activityInjector(): AndroidInjector<Activity> = dispatchingAndroidInjector
override fun onCreate() {
super.onCreate()
DaggerAppComponent
.builder()
.bindApplication(this)
.build()
.inject(this)
}
}
Is there anything else I am missing in the hooking of the modules and components?
This "fun inject(app: Application)" should be
fun inject(app: App)