2

koin works fine with most of my devices of same model but it cause crash in single device with the IllegalStateException, i have give android context as applicationContext but still it is cause crash.

Before Updating to Latest Version it was throwing "Caused by: java.lang.IllegalStateException: KoinApplication has not been started" but after update

E/AndroidRuntime: FATAL EXCEPTION: main
Process: #######, PID: 31641
java.lang.RuntimeException: Unable to start activity ComponentInfo{###.activities.SplashScreenActivity}: java.lang.IllegalStateException: No Koin Context configured. Please use startKoin or koinApplication DSL.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3044)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3122)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1819)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:192)
at android.app.ActivityThread.main(ActivityThread.java:6892)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:556)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:875)
Caused by: java.lang.IllegalStateException: No Koin Context configured. Please use startKoin or koinApplication DSL.
at org.koin.core.context.KoinContextHandler.getContext(KoinContextHandler.kt:29)
at org.koin.core.context.KoinContextHandler.get(KoinContextHandler.kt:35)
at org.koin.android.ext.android.ComponentCallbackExtKt.getKoin(ComponentCallbackExt.kt:15)
at org.koin.androidx.viewmodel.ext.android.ViewModelStoreOwnerExtKt.getKoin(ViewModelStoreOwnerExt.kt:63)
at org.koin.androidx.viewmodel.ext.android.ViewModelStoreOwnerExtKt.getViewModel(ViewModelStoreOwnerExt.kt:60)
at .SplashScreenActivity$$special$$inlined$viewModel$1.invoke(ViewModelStoreOwnerExt.kt:45)
at #######.activities.SplashScreenActivity$$special$$inlined$viewModel$1.invoke(Unknown Source:0)
at kotlin.UnsafeLazyImpl.getValue(Lazy.kt:81)
at #########activities.SplashScreenActivity.getMViewModel(Unknown Source:7)
at #########.activities.SplashScreenActivity.onCreate(SplashScreenActivity.kt:86)
at android.app.Activity.performCreate(Activity.java:7147)
at android.app.Activity.performCreate(Activity.java:7138)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1219)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2997)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3122) 
at android.app.ActivityThread.-wrap11(Unknown Source:0) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1819) 
at android.os.Handler.dispatchMessage(Handler.java:106) 
at android.os.Looper.loop(Looper.java:192) 
at android.app.ActivityThread.main(ActivityThread.java:6892) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:556) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:875) 

i am starting koin in application class:

startKoin { // declare used Android context androidContext(this@QairosApplication) // declare modules modules(myModule) }

Khalid Saeed
  • 131
  • 2
  • 8

1 Answers1

10

In your manifest file, you need to give the name of the class where you use startKoin{}. For example, if you start Koin in a class called BaseApplication, in your manifest, it should look like this :

 <application
    android:name=".BaseApplication"
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">

And in BaseApplication Class :

class BaseApplication : Application() {
    override fun onCreate() {
        super.onCreate()

        startKoin {
            androidLogger()
            androidContext(this@BaseApplication)
            modules(listOf(module1, module2))
        }
}
Xarybdis
  • 157
  • 6