Search code examples
androidkoin

StandAloneContext Koin instance is null


As I added Koin to a project, I keep running into the following error. StandAloneContext Koin instance is null

implementation 'org.koin:koin-android:1.0.2'

Modules.kt

val UIModule: Module = module {
    factory<MainContract.Presenter> { MainPresenter() }
}

val appModules = listOf(UIModule)

App.kt

class App : Application() {

    private val TAG : String = Application::class.java.name

    override fun onCreate() {
        super.onCreate()

        startKoin(this, appModules)
    }
}

Solution

  • After a whole afternoon wasted of me trying to figure out this issue, and short of just dropping Koin altogether, I checked my App class one more time and finally paid attention to the yellow warning highlight from Android Studio over the App class....

    Turns out all I needed to solve this was to add the application class to the manifest... 🤦‍♀️🤦‍♀️🤦‍♀️

    AndroidManifest.xml

    <application android:name=".app.App" ... />
    

    If this helps even 1 person not waste a whole 4 hours, then it was worth me posting this question/answer here.

    Cheers!