Hi, anyone face the issue: `Uncaught Kotlin except...
# koin
t
Hi, anyone face the issue:
Uncaught Kotlin exception: kotlin.IllegalStateException: KoinApplication has not been started
in iOS? I have initialized koin in init() block (with swiftui) and UIApplicationDelegate (with UIkit). But ios application keep crashed. Please help me!!
a
in Confetti app, they have something like that:
Copy code
fun initKoin(appDeclaration: KoinAppDeclaration = {}) =
    startKoin {
        modules(commonModule())
        appDeclaration()
    }

// called by iOS client
fun initKoin() = initKoin() {}
do you have the same kind of init/start function?
t
Yes I have this setup, and I also tried both in swift ui and ui kit in ios.
j
There seems to be some code that is accessing your dependencies before the code that initializes them. Make sure the
initKoin
code is called first before anything else.
t
Yes I think so. Compose code access my dependencies so I tried to init koin first then create ios view controller later. But it's keeping crash. Let me take a picture of my code.
Here is my code @arnaud.giuliani @Jeff Lockhart .Sorry for mentioning you guys. Please take a look iOSApp.swift
Copy code
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
    
    var window: UIWindow?
    
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
        KoinHelperKt.doInitKoin()
        window = UIWindow(frame: UIScreen.main.bounds)
        window?.rootViewController = IOSMainViewKt.MainViewController()
        window?.makeKeyAndVisible()
        return true
    }
}
doInitKoin is helper function to init koin application
Copy code
fun doInitKoin() = startKoin {
    modules(commonModule() + storeModule() + posSdkModule() + posTerminalSdkModule())
}
MainViewController is compose multiplatform function. I'm accessing koin dependencies inside it:
Copy code
fun MainViewController(): UIViewController = ComposeUIViewController { MainScene() }
I config a logger in iOS and I see Koin already loaded but then application got crashed
Copy code
[Koin]: loaded 34 definitions in 0.605958 ms
Uncaught Kotlin exception: kotlin.IllegalStateException: KoinApplication has not been started
Hi anyone can help me please:(
j
I'd debug by putting a break point in the dependency constructor and Koin init factory and confirm it's run before the crash. Also confirm where in your code the crash is originating from and why that's executing before Koin is initialized.
150 Views