Johan Reitan
10/11/2024, 8:44 AMinitKoin()
function, and the Presentation module is exposed to Swift.
I’ve made sure to call initKoin()
from the iOS app’s init:
@main
struct iOSApp: App {
init() {
KoinKt.doInitKoin()
}
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
I have made a helper KoinComponent
to be able to inject my component:
class EditViewModelHelper : KoinComponent {
val viewModel: EditViewModel by inject()
}
But when I try to inject my component in Swift, IllegalStateException: KoinApplication has not been started
is thrown:
struct ContentView: View {
let viewModel = EditViewModelHelper().viewModel
// ...
}
Full stacktrace in thread.
I have also tried injecting a simple class with no dependencies to rule out the issue of missing exported binaries from the thread I linked to above.
Any idea what causes this?Johan Reitan
10/11/2024, 8:48 AMUncaught Kotlin exception: kotlin.IllegalStateException: KoinApplication has not been started
at 0 Presentation 0x106186257 kfun:kotlin.Throwable#<init>(kotlin.String?){} + 119
at 1 Presentation 0x10617f757 kfun:kotlin.Exception#<init>(kotlin.String?){} + 115
at 2 Presentation 0x10617f977 kfun:kotlin.RuntimeException#<init>(kotlin.String?){} + 115
at 3 Presentation 0x10617ff17 kfun:kotlin.IllegalStateException#<init>(kotlin.String?){} + 115
at 4 Presentation 0x1064fe3fb kfun:org.koin.core.context.MutableGlobalContext#get(){}org.koin.core.Koin + 275
at 5 Presentation 0x106501723 kfun:org.koin.core.context.KoinContext#get(){}org.koin.core.Koin-trampoline + 99
at 6 Presentation 0x1064e5abb kfun:org.koin.core.component.KoinComponent#getKoin(){}org.koin.core.Koin + 159
at 7 Presentation 0x10650163f kfun:org.koin.core.component.KoinComponent#getKoin(){}org.koin.core.Koin-trampoline + 99
at 8 Presentation 0x105565757 kfun:presentation.features.edit.EditViewModelHelper.<init>$lambda$0#internal + 607
at 9 Presentation 0x1055658eb kfun:presentation.features.edit.EditViewModelHelper.$<init>$lambda$0$FUNCTION_REFERENCE$1.invoke#internal + 87
at 10 Presentation 0x1062afca7 kfun:kotlin.Function0#invoke(){}1:0-trampoline + 99
at 11 Presentation 0x106197fbb kfun:kotlin.native.concurrent.SafePublicationLazyImpl#<get-value>(){}1:0 + 459
at 12 Presentation 0x1062b1c8f kfun:kotlin.Lazy#<get-value>(){}1:0-trampoline + 99
at 13 Presentation 0x10556549f kfun:presentation.features.edit.EditViewModelHelper#<get-viewModel>(){}presentation.features.edit.EditViewModel + 195
at 14 Presentation 0x1055793b7 objc2kotlin_kfun:presentation.features.edit.EditViewModelHelper#<get-viewModel>(){}presentation.features.edit.EditViewModel + 159
at 15 iosApp.debug.dylib 0x10059c9cf $s6iosApp11ContentViewVACycfC + 83 (ContentView.swift:5:40)
at 16 iosApp.debug.dylib 0x10059e1ff $s6iosApp6iOSAppV4bodyQrvgAA11ContentViewVycfU_ + 55 (iOSApp.swift:12:4)
at 17 SwiftUI 0x1d19187ff $s7SwiftUI4MenuV_7contentACyAA4TextVq_GAA18LocalizedStringKeyV_q_yXEtcAFRszrlufcq_yXEfU_Tm + 87
at 18 SwiftUICore 0x1d2a51eef $s7SwiftUI16ViewBodyAccessorV06updateD02of7changedyx_SbtFTf4nnd_n + 955
at 19 SwiftUICore 0x1d2b37817 $s7SwiftUI10StaticBody33_A4C1D658B3717A3062FEFC91A812D6EBLLV11updateValueyyFyyXEfU_ + 343
at 20 SwiftUICore 0x1d2b37403 $s7SwiftUI10StaticBody33_A4C1D658B3717A3062FEFC91A812D6EBLLV11updateValueyyF + 367
at 21 SwiftUICore 0x1d2bc400f $s14AttributeGraph0A0VyACyxGqd__c5ValueQyd__RszAA12StatefulRuleRd__lufcADSPyqd__GXEfU_ySv_So11AGAttributeatcyXEfU_ySv_AJtcfu_TA + 27
at 22 AttributeGraph 0x1bdf35f7b _ZN2AG5Graph11UpdateStack6updateEv + 531
at 23 AttributeGraph 0x1bdf367cb _ZN2AG5Graph16update_attributeENS_4data3ptrINS_4NodeEEEj + 431
at 24 AttributeGraph 0x1bdf3e437 _ZN2AG5Graph20input_value_ref_slowENS_4data3ptrINS_4NodeEEENS_11AttributeIDEjjPK15AGSwiftMetadataRhl + 715
at 25 AttributeGraph 0x1bdf53f9b AGGraphGetValue + 231
at 26 SwiftUICore 0x1d2b37b9f $s7SwiftUI11DynamicBody33_A4C1D658B3717A3062FEFC91A812D6EBLLV11updateValueyyF + 411
at 27 SwiftUICore 0x1d2bc400f $s14AttributeGraph0A0VyACyxGqd__c5ValueQyd__RszAA12StatefulRuleRd__lufcADSPyqd__GXEfU_ySv_So11AGAttributeatcyXEfU_ySv_AJtcfu_TA + 27
at 28 AttributeGraph 0x1bdf35f7b _ZN2AG5Graph11UpdateStack6updateEv + 531
at 29 AttributeGraph 0x1bdf367cb _ZN2AG5Graph16update_attributeENS_4data3ptrINS_4NodeEEEj + 431
at 30 AttributeGraph 0x1bdf3e437 _ZN2AG5Graph20input_value_ref_slowENS_4data3ptrINS_4NodeEEENS_11AttributeIDEjjPK15AGSwiftMetadataRhl + 715
at 31 AttributeGraph 0x1bdf53f9b AGGraphGetValue + 231
at 32 SwiftUICore 0x1d288949b $s7SwiftUI20DynamicViewContainer031_3FB6ABB0477B815AB3C89DD5EDC9F0M0LLV11updateValueyyFAA03AnyD0V_Tg5 + 75
at 33 SwiftUICore 0x1d2896d13 $s14AttributeGraph0A0VyACyxGqd__c5ValueQyd__RszAA12StatefulRuleRd__lufcADSPyqd__GXEfU_ySv_So11AGAttributeatcyXEfU_ySv_AJtcfu_7SwiftUI20DynamicViewContainer031_3FB6ABB0477B815AB3C89DD5EDC9F0S0LLVAEVyAK03AnyJ0V_G_ANyAQGTgm5 + 19
at 34 AttributeGraph 0x1bdf35f7b _ZN2AG5Graph11UpdateStack6updateEv + 531
at 35 AttributeGraph 0x1bdf367cb _ZN2AG5Graph16update_attributeENS_4data3ptrINS_4NodeEEEj + 431
at 36 AttributeGraph 0x1bdf44067 _ZN2AG8Subgraph6updateEj + 827
at 37 SwiftUICore 0x1d2fc51d7 $s7SwiftUI9ViewGraphC13updateOutputs33_7D9EDEF832940A362646A6E979F296C8LL5asyncySb_tF + 339
at 38 SwiftUICore 0x1d2fbb8a7 $s7SwiftUI16ViewRendererHostPAAE6render8interval17updateDisplayList15targetTimestampySd_SbAA4TimeVSgtFyyXEfU_yyXEfU0_ + 147
at 39 SwiftUICore 0x1d2fbb6bf $s7SwiftUI16ViewRendererHostPAAE6render8interval17updateDisplayList15targetTimestampySd_SbAA4TimeVSgtFyyXEfU_ + 535
at 40 SwiftUICore 0x1d2fb951b $s7SwiftUI16ViewRendererHostPAAE6render8interval17updateDisplayList15targetTimestampySd_SbAA4TimeVSgtF + 423
at 41 SwiftUI 0x1d23548bf $s7SwiftUI14_UIHostingViewC14layoutSubviewsyyF + 583
at 42 SwiftUI 0x1d2354923 $s7SwiftUI14_UIHostingViewC14layoutSubviewsyyFTo + 31
at 43 UIKitCore 0x18601c0c3 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 2403
at 44 QuartzCore 0x18b06ceaf _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 431
at 45 QuartzCore 0x18b077c33 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 123
at 46 QuartzCore 0x18afacc57 _ZN2CA7Context18commit_transactionEPNS_11TransactionEdPd + 463
at 47 QuartzCore 0x18afdb467 _ZN2CA11Transaction6commitEv + 651
at 48 UIKitCore 0x185abb7b3 __34-[UIApplication _firstCommitBlock]_block_invoke_2 + 31
at 49 CoreFoundation 0x18041b0eb __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 19
at 50 CoreFoundation 0x18041a823 __CFRunLoopDoBlocks + 351
at 51 CoreFoundation 0x1804150c7 __CFRunLoopRun + 811
at 52 CoreFoundation 0x18041495f CFRunLoopRunSpecific + 535
at 53 GraphicsServices 0x190183b0f GSEventRunModal + 159
at 54 UIKitCore 0x185aa2b3f -[UIApplication _run] + 795
at 55 UIKitCore 0x185aa6d37 UIApplicationMain + 123
at 56 SwiftUI 0x1d1e2eab3 $s7SwiftUI17KitRendererCommon33_ACC2C5639A7D76F611E170E831FCA491LLys5NeverOyXlXpFAESpySpys4Int8VGSgGXEfU_ + 163
at 57 SwiftUI 0x1d1e2e7db $s7SwiftUI6runAppys5NeverOxAA0D0RzlF + 83
at 58 SwiftUI 0x1d1b70c8b $s7SwiftUI3AppPAAE4mainyyFZ + 147
at 59 iosApp.debug.dylib 0x10059e4b7 $s6iosApp6iOSAppV5$mainyyFZ + 39
at 60 iosApp.debug.dylib 0x10059e563 __debug_main_executable_dylib_entry_point + 11 (iOSApp.swift:5:8)
at 61 dyld 0x1002fd40f 0x0 + 4298101775
at 62 ??? 0x100476273 0x0 + 4299645555
Johan Reitan
10/11/2024, 10:06 AMAlexandru Caraus
10/11/2024, 10:25 AMFrançois
10/11/2024, 10:41 AMJohan Reitan
10/11/2024, 11:41 AMembedAndSignAppleFrameworkForXcode
in the Build Phases, and that worked fine! It must have been an issue with how the unofficial Apple Gradle plugin that Amper uses is generating the XCode project.arnaud.giuliani
10/16/2024, 2:16 PM