Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

StandAloneContext Koin instance is null

Tags:

android

koin

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)
    }
}
like image 480
murielg Avatar asked Dec 03 '22 10:12

murielg


1 Answers

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!

like image 59
murielg Avatar answered Dec 04 '22 22:12

murielg