I am learning kotlin using koin. While running the application in catlog I see the following message.
java.lang.IllegalStateException: KoinApplication has not been started
though I have used startKoin in MyApplication
class MyApplication : Application() {
var listOfModules = module {
single { GitHubServiceApi() }
}
override fun onCreate() {
super.onCreate()
startKoin {
androidLogger()
androidContext(this@MyApplication)
modules(listOfModules)
}
}
}
I found the issue where I have done my mistake.I was suppose to add the MyApplcation name in mainfest.xml
Adding "android:name=".TheApplication" in the Manifest file solved the issue.
android:name=".TheApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_app_icon_round"
android:supportsRtl="true"
android:theme="@style/Theme.Shrine">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
"android:name=".TheApplication" is the Class Name from Koin
class TheApplication : Application() {
override fun onCreate() {
super.onCreate()
if (BuildConfig.DEBUG) {
Timber.plant(Timber.DebugTree())
}
startKoin {
androidLogger()
androidContext(androidContext = this@TheApplication)
modules(
listOfModules
)
}
}
}
Basically, you need to give the name of the class where you called startKoin() method, in the Manifest as an application name. And this will let your configure logging, properties loading and modules. Check this out: https://doc.insert-koin.io/#/koin-core/dsl
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With