Search code examples
androidandroid-studiokotlinkoin

Is it possible to build a project with Dynamic feature modules and Koin?


I have an app with different modules but the project is growing and we need to split the project in different Dynamic feature modules because the users (probably) would not need all the features. My problem is that Koin needs to be started from the Application class with all the koin modules that the app is going to load but from that class I don't know which modules I have to load and :app modules does not import the other modules in gradle's dependencies (the other modules have to implement :app module). My question is if it is a way to load Koin modules from an Activity in :app or the other loaded features.


Solution

  • At the end, reading the documentation, I have found the solution. Instad of using startKoin with all my feature modules, I can use startKoin(...) with no modules or base modules and then loadKoinModules(...) (more) in each dynamic feature to load their koin modules. As a tip about dynamic features, it is good to have an interface with an entry point function that every feature implements to start the modules only once.