Этот код отлично работает в Java, но имеет неопределенную проблему в Kotlin
Задача :
ошибка: [Dagger / MissingBinding] ru.terrakok.cicerone.Router не может быть предоставлен без конструктора @Inject или метода, аннотированного @ Provides.
открытый абстрактный void inject (@ org.jetbrains.annotations.NotNull ()
ru.terrakok.cicerone. Маршрутизатор вводится при
com.setname.dagger2ciceronelearning.presentation.main.MainActivity.mRouter
com.setname.dagger2ciceronelearning.presentation.main.MainActivity вводится в
com.setname.dagger2ciceronelearning.di.AppComponent.inject (com.setname.dagger2ciceronelearning.presentation.main.MainActivity)
AppComponent
@Singleton
@Component(modules = arrayOf(NavigationModule::class))
interface AppComponent {
fun inject(mainActivity: MainActivity)
fun inject(fragmentOne: FragmentOne)
fun inject(fragmentTwo: FragmentTwo)
}
NavigationModule
@Module
class NavigationModule {
private val firstLevelNavigation: Cicerone<Router> = Cicerone.create()
private val secondLevelNavigation: Cicerone<Router> = Cicerone.create()
@Provides
@Singleton
@Named(Navigation.ROUTER_FIRST_LEVEL)
fun provideFirstLevelRouter(): Router = firstLevelNavigation.router
@Provides
@Singleton
@Named(Navigation.ROUTER_SECOND_LEVEL)
fun provideSecondLevelRouter(): Router = secondLevelNavigation.router
@Provides
@Singleton
@Named(Navigation.NAV_HOLDER_FIRST_LEVEL)
fun provideFirstLevelNavigatorHolder(): NavigatorHolder = firstLevelNavigation.navigatorHolder
@Provides
@Singleton
@Named(Navigation.NAV_HOLDER_SECOND_LEVEL)
fun provideSecondLevelNavigationHolder(): NavigatorHolder = secondLevelNavigation.navigatorHolder
}
LearingApp
class LearningApp : Application() {
companion object {
lateinit var appComponent: AppComponent
}
override fun onCreate() {
super.onCreate()
appComponent = DaggerAppComponent
.builder()
.build()
}
}
MainActivity
class MainActivity : AppCompatActivity() {
@Inject
@Named(Navigation.ROUTER_FIRST_LEVEL)
lateinit var mRouter: Router
@Inject
@Named(Navigation.NAV_HOLDER_FIRST_LEVEL)
lateinit var mNavigatorHolder: NavigatorHolder
private lateinit var mNavigator:Navigator
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
LearningApp.appComponent.inject(this)
mNavigator = SupportAppNavigator(this, R.id.main_container)
mRouter.newRootScreen(Screens.FragmentOneScreen())
}
override fun onResume() {
super.onResume()
mNavigatorHolder.setNavigator(mNavigator)
}
override fun onPause() {
mNavigatorHolder.removeNavigator()
super.onPause()
}
}