Hello, I'm facing the following crash in my iOS ap...
# koin
e
Hello, I'm facing the following crash in my iOS app. It happens when the koin dependency tree is loaded. It's happening in a few versions of iOS (17.5.1, 18.3.2, 16.6.1). At the most recent version of iOS the crash not happens... My Koin version is 4.0.4 From : crashlytics
Copy code
Crashed: com.apple.main-thread
0x14f28 class_rw_t::methods() const
0x125a8 class_copyMethodList
0x21ae42c createTypeInfo(objc_class*, TypeInfo const*, TypeInfo const*)
0x21ae274 getOrCreateTypeInfo(objc_class*)
0x1de4850 kfun:kotlinx.cinterop.internal.ObjectiveCKClassImpl#hashCode(){}<http://kotlin.Int|kotlin.Int> + 1852 (Primitives.kt:1852)
0x1e2bd7c kfun:kotlin.collections.HashMap.findKey#internal + 40 (Any.kt:40)
0x1e28e2c kfun:kotlin.collections.HashMap#get(1:0){}1:1? + 111 (HashMap.kt:111)
0x1f151b0 kfun:co.touchlab.stately.collections.ConcurrentMutableMap.ConcurrentMutableMap$get$1.invoke#internal + 27 (ConcurrentMutableMap.kt:27)
0x1f0f690 kfun:co.touchlab.stately.concurrency.Synchronizable#runSynchronized(kotlin.Function0<0:0>){0§<kotlin.Any?>}0:0 + 1 ([K][Suspend]Functions:1)
0x1f13d68 kfun:co.touchlab.stately.collections.ConcurrentMutableMap#get(1:0){}1:1? + 27 (ConcurrentMutableMap.kt:27)
0x1f243cc kfun:org.koin.ext#getFullName__at__kotlin.reflect.KClass<*>(){}kotlin.String + 85 (Map.kt:85)
0x1f1c94c kfun:org.koin.core.module.Module#indexPrimaryType(org.koin.core.instance.InstanceFactory<*>){} + 100 (BeanDefinition.kt:100)
0x217a5a0 kfun:my.package.core.network.networkModule$1.$<bridge-DNN>invoke(org.koin.core.module.Module){}#internal + 112 (Module.kt:112)
0x1f2408c kfun:org.koin.dsl#module(kotlin.Boolean;kotlin.Function1<org.koin.core.module.Module,kotlin.Unit>){}org.koin.core.module.Module + 38 (ModuleDSL.kt:38)
0x21843fc kfun:my.package.startComposeModules$1.$<bridge-DNN>invoke(org.koin.core.KoinApplication){}#internal + 33 (ModuleDSL.kt:33)
0x1f27ba8 kfun:org.koin.core.context.MutableGlobalContext#startKoin(kotlin.Function1<org.koin.core.KoinApplication,kotlin.Unit>){}org.koin.core.KoinApplication + 1 ([K][Suspend]Functions:1)
0x219c764 objc2kotlin_kfun:my.package#startComposeModules(kotlin.String;kotlin.Function0<platform.Foundation.NSURLCredential?>){} + 41 (DefaultContextExt.kt:41)
0xae2b8 specialized AppDelegate.application(_:didFinishLaunchingWithOptions:) + 25 (AppDelegate.swift:25)
0xacfe8 @objc AppDelegate.application(_:didFinishLaunchingWithOptions:) (<compiler-generated>)
Do you have any clues? My coworker tried to increase the koin version to 4.1.0 but the crash still happens but with a different stracktrace
Copy code
Can't show file for stack frame : <DBGLLDBStackFrame: 0x367d4abb0> - stackNumber:4 - name:kfun:kotlinx.cinterop.internal.ObjectiveCKClassImpl#hashCode(){}<http://kotlin.Int|kotlin.Int> [inlined] kfun:kotlinx.cinterop.internal.ObjectiveCKClassImpl#<get-typeInfo>(){}kotlin.native.internal.NativePtr [inlined]. 
The file path does not exist on the file system: /opt/buildAgent/work/2d153abd4d2c0600/kotlin/kotlin-native/Interop/Runtime/src/native/kotlin/kotlinx/cinterop/internal/ObjectiveCKClassImpl.kt
1
a
are you trying to expose iOS swift class or something?
snippets can help us to see what you try to do. Else it shouldn't break
e
Hello. I figured it out. I was trying to provide an NSURLCredential object to use with Ktor. This object was created on the iOS side, but it could be null (on first use). It's tricky because it seems like Koin cannot handle nullable Objective-C objects. The solution was simple: just wrap it in another object and always create it on iOS side. Example:
Copy code
data class ConnectionCredential(
    val urlCredential: NSURLCredential?,
)

fun networkModule(   
    urlCredential: (() -> ConnectionCredential),
) {
    loadKoinModules(
        module {
            single<ConnectionCredential> { urlCredential() }
        },
    )
    ...
}
a
Cool 🙂 👍