https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
b

BollywoodVillain

11/25/2020, 12:54 PM
Copy code
isMainThread: true
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.native.concurrent.InvalidMutabilityException: mutation attempt of frozen com.berlin.kmm_demo.shared.ApiService@2a37878
    at 0   shared                              0x0000000100c192dd kfun:kotlin.Throwable#<init>(kotlin.String?){} + 93 (/Users/teamcity/buildAgent/work/cae0e6559deed4c4/runtime/src/main/kotlin/kotlin/Throwable.kt:23:37)
    at 1   shared                              0x0000000100c121cb kfun:kotlin.Exception#<init>(kotlin.String?){} + 91 (/Users/teamcity/buildAgent/work/cae0e6559deed4c4/runtime/src/main/kotlin/kotlin/Exceptions.kt:23:44)
    at 2   shared                              0x0000000100c1238b kfun:kotlin.RuntimeException#<init>(kotlin.String?){} + 91 (/Users/teamcity/buildAgent/work/cae0e6559deed4c4/runtime/src/main/kotlin/kotlin/Exceptions.kt:34:44)
    at 3   shared                              0x0000000100c4793b kfun:kotlin.native.concurrent.InvalidMutabilityException#<init>(kotlin.String){} + 91 (/Users/teamcity/buildAgent/work/cae0e6559deed4c4/runtime/src/main/kotlin/kotlin/native/concurrent/Freezing.kt:22:60)
    at 4   shared                              0x0000000100c491f2 ThrowInvalidMutabilityException + 690 (/Users/teamcity/buildAgent/work/cae0e6559deed4c4/runtime/src/main/kotlin/kotlin/native/concurrent/Internal.kt:92:11)
    at 5   shared                              0x0000000100d4136c MutationCheck + 108
    at 6   shared                              0x0000000100bb7ce7 kfun:com.berlin.kmm_demo.shared.ApiService#<init>(){} + 455
    at 7   shared                              0x0000000100bbc743 objc2kotlin + 163
    at 8   iosApp                              0x0000000100ae655f $sSo16SharedApiServiceCABycfC + 31
    at 9   iosApp                              0x0000000100ae6467 $s6iosApp12getLocationsyyF + 39 (/Users/skhawase/skunkworks/KMM_Demo/iosApp/iosApp/ContentView.swift:13:1)
    at 10  iosApp                              0x0000000100ae6eaa $s6iosApp11ContentViewV4bodyQrvgyycfU_ + 442 (/Users/skhawase/skunkworks/KMM_Demo/iosApp/iosApp/ContentView.swift:20:9)
    at 11  SwiftUI                             0x00007fff55f13d0c $sIeg_ytIegr_TR + 12
    at 12  SwiftUI                             0x00007fff55e22b01 $sIeg_ytIegr_TRTA + 17
    at 13  SwiftUI                             0x00007fff55f13d2c $sytIegr_Ieg_TR + 12
    at 14  SwiftUI                             0x00007fff55f13d0c $sIeg_ytIegr_TR + 12
    at 15  SwiftUI                             0x00007fff55e22b01 $sIeg_ytIegr_TRTA + 17
    at 16  SwiftUI                             0x00007fff55e22c09 $sIeg_ytIegr_TRTA.8 + 9
    at 17  SwiftUI                             0x00007fff5636e239 $s7SwiftUI16ViewRendererHostPAAE6render8interval17updateDisplayListySd_SbtFyyXEfU_ + 1657
    at 18  SwiftUI                             0x00007fff5636d2f7 $s7SwiftUI16ViewRendererHostPAAE6render8interval17updateDisplayListySd_SbtF + 343
    at 19  SwiftUI                             0x00007fff564d4e41 $s7SwiftUI14_UIHostingViewC14layoutSubviewsyyF + 241
    at 20  SwiftUI                             0x00007fff564d4e65 $s7SwiftUI14_UIHostingViewC14layoutSubviewsyyFTo + 21
    at 21  UIKitCore                           0x00007fff24bcd686 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 2874
    at 22  QuartzCore                          0x00007fff27a5ae67 -[CALayer layoutSublayers] + 258
    at 23  QuartzCore                          0x00007fff27a61319 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 575
    at 24  QuartzCore                          0x00007fff27a6d071 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 65
    at 25  QuartzCore                          0x00007fff279ad158 _ZN2CA7Context18commit_transactionEPNS_11TransactionEdPd + 496
    at 26  QuartzCore                          0x00007fff279e3ef3 _ZN2CA11Transaction6commitEv + 783
    at 27  UIKitCore                           0x00007fff2468ab96 __34-[UIApplication _firstCommitBlock]_block_invoke_2 + 81
    at 28  CoreFoundation                      0x00007fff203a85db __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
    at 29  CoreFoundation                      0x00007fff203a79ef __CFRunLoopDoBlocks + 434

Process finished with exit code 0
m

Maurice Jouvet

11/27/2020, 8:28 AM
Hey what is the method that you call from iOS? Just the header of the method.
b

BollywoodVillain

12/07/2020, 12:05 PM
I fixed the issue by moving the Json formatter inside the
KotlinXSerializer
init(). You can find the final working source code here: https://github.com/samkhawase/Kotlin_MPP_Demo