Closed
Description
Describe the bug
The bug appears when you want to get
a Objective-C class
Koin version 3.0.1-alpha-3
Edit: 3.1.0
remains the same
Edit: 3.1.2
remains the same
a simple example to demonstrate
// works
fun initIOS(userDefaults: NSUserDefaults) = initClient(
module {
single<Settings> { AppleSettings(userDefaults) }
}
)
//fails
fun initIOS(userDefaults: NSUserDefaults) = initClient(
module {
single<NSUserDefaults> { userDefaults }
single<Settings> { AppleSettings(get()) }
}
)
It compiles fine but getting run time exception on IOS, the log below
Debug: (Kermit) starting koin
Function doesn't have or inherit @Throws annotation and thus exception isn't propagated from Kotlin to Objective-C/Swift as NSError.
It is considered unexpected and unhandled instead. Program will be terminated.
Uncaught Kotlin exception: kotlin.IllegalStateException: KClass for Objective-C classes is not supported yet
at 0 CCC 0x000000010b61082f kfun:kotlin.Throwable#<init>(kotlin.String?){} + 95
at 1 CCC 0x000000010b608f8d kfun:kotlin.Exception#<init>(kotlin.String?){} + 93
at 2 CCC 0x000000010b6091fd kfun:kotlin.RuntimeException#<init>(kotlin.String?){} + 93
at 3 CCC 0x000000010b6098ad kfun:kotlin.IllegalStateException#<init>(kotlin.String?){} + 93
at 4 CCC 0x000000010b6513cf kfun:kotlin.native.internal.KClassUnsupportedImpl#hashCode(){}kotlin.Int + 335
at 5 CCC 0x000000010b8de31f kfun:org.koin.core.definition.BeanDefinition#hashCode(){}kotlin.Int + 383
at 6 CCC 0x000000010b626072 kfun:kotlin.collections.HashMap.hash#internal + 226
at 7 CCC 0x000000010b627736 kfun:kotlin.collections.HashMap#addKey(1:0){}kotlin.Int + 486
at 8 CCC 0x000000010b6310ff kfun:kotlin.collections.HashSet#add(1:0){}kotlin.Boolean + 207
at 9 CCC 0x000000010b8e77a7 kfun:org.koin.core.module#addDefinition@kotlin.collections.HashSet<org.koin.core.definition.BeanDefinition<*>>(org.koin.core.definition.BeanDefinition<*>){} + 439
at 10 CCC 0x000000010b472354 kfun:com.github.mustafaozhan.ccc.client.di.initIOS$lambda-1#internal + 1252
at 11 CCC 0x000000010b472541 kfun:com.github.mustafaozhan.ccc.client.di.$initIOS$lambda-1$FUNCTION_REFERENCE$52.invoke#internal + 97
at 12 CCC 0x000000010b4725c1 kfun:com.github.mustafaozhan.ccc.client.di.$initIOS$lambda-1$FUNCTION_REFERENCE$52.$<bridge-UNNN>invoke(-1:0){}#internal + 97
at 13 CCC 0x000000010b8fefed kfun:org.koin.dsl#module(kotlin.Boolean;kotlin.Boolean;kotlin.Function1<org.koin.core.module.Module,kotlin.Unit>){}org.koin.core.module.Module + 381
at 14 CCC 0x000000010b8ff184 kfun:org.koin.dsl#module$default(kotlin.Boolean;kotlin.Boolean;kotlin.Function1<org.koin.core.module.Module,kotlin.Unit>;kotlin.Int){}org.koin.core.module.Module + 276
at 15 CCC 0x000000010b471a82 kfun:com.github.mustafaozhan.ccc.client.di#initIOS(platform.Foundation.NSUserDefaults){}org.koin.core.KoinApplication + 354
at 16 CCC 0x000000010b5aaec8 objc2kotlin.3553 + 216
at 17 CCC 0x000000010b2a43d2 $s3CCC6CCCAppVACycfC + 18
at 18 CCC 0x000000010b2a4bc9 $s3CCC6CCCAppV7SwiftUI3AppAadEPxycfCTW + 9
at 19 SwiftUI 0x000000010eebc65f $s7SwiftUI3AppPAAE4mainyyFZ + 47
at 20 CCC 0x000000010b2a4b61 $s3CCC6CCCAppV5$mainyyFZ + 33
at 21 CCC 0x000000010b2a4be4 main + 20
at 22 libdyld.dylib 0x0000000112b6895d start + 1
at 23 ??? 0x0000000000000001 0x0 + 1
CoreSimulator 725.10 - Device: iPhone 11 Pro Max (1C7C1A0E-2FE5-47FF-AAB1-57530F0DAD34) - Runtime: iOS 14.0 (18A5319g) - DeviceType: iPhone 11 Pro Max
Metadata
Metadata
Assignees
Type
Projects
Relationships
Development
No branches or pull requests
Activity
Baileypollard commentedon Apr 8, 2021
Do we know the cause of this yet?
mustafaozhan commentedon Jun 19, 2021
@Baileypollard yes, from the log I understand that koin doesn't support it currently.
KClass for Objective-C classes is not supported yet
JohNan commentedon Aug 20, 2021
I have run into the same problem. My workaround for now is to create a wrapper class in kotlin.
Seems to work :)
slipdef commentedon Sep 2, 2021
Any progress on that? It blocks us to use Koin to resolve iOS dependencies.
osrl commentedon Oct 18, 2021
Is this related to what I've encountered?
I can't
get
from ios if the dependency is defined with interface:Error:
Uncaught Kotlin exception: org.koin.core.error.NoBeanDefFoundException: No definition found for class:'com.foo.main.ktor.TokenSourceImpl'. Check your definitions!
zakrodionov commentedon Oct 20, 2021
Same issue in Kmm
osrl commentedon Oct 21, 2021
My issue was not related to this. I needed to use
ObjCProtocol
instead, if anyone is interested.mustafaozhan commentedon Oct 23, 2021
@JohNan yes I confirm also,
It works as below
and then I can use it
but we can not take this as solution it is just a workaround, I think koin should support this :)
mykola-dev commentedon Nov 8, 2021
i would really appreciate if someone explain if this is a kmm limitation or the koin library issue? just curious why we can't use ios specific dependencies directly
philhinco commentedon Jan 18, 2022
@osrl What do you mean with ObjCProtocol? I‘m trying to koin.get an interface that I defined in KMP and implemented in iOS, but it fails currently.
osrl commentedon Jan 18, 2022
objCProtocol
instead ofobjCClass
as parameter namephilhinco commentedon Jan 18, 2022
@osrl Ah, I see. And what would be the way to call it from Swift? I‘m trying to create a function or property wrapper but can‘t get it to work. The plain call to my Kotlin extension function I wrote works without problem, but I would want to make an abstraction that does the whole dance with
as
casting etc.stale commentedon May 18, 2022
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
mustafaozhan commentedon May 18, 2022
Still looking forward to seeing this issue fixed 🙂
15 remaining items