kotlin-hands-on / kmp-networking-and-data-storage

Other
252 stars 69 forks source link

Ios application crashes in the emulator - comment 6ce52dd on upd-final branch #19

Closed jkbredsquiggles closed 1 year ago

jkbredsquiggles commented 2 years ago

Hi:

First some context.

I tried to run the demo using the current version of Android Studio (2021.2.1 Patch 1 built on May 18, 2022), Kotlin (Android studio won't display the full plugin version but it looks like it was built on Jul 7, 2022 and it's in the 1.7 series) and it's associated libraries ( current versions of the serialization, sql delight, and tor libraries). I had issues running the Android app, an exception trying to deserialize the response from spacex service.

Because I had manually tried to update the project references and this is one of my first hmm projects, I gave up on that experiment and attempted to use the current version of the demo on the bpd-final branch.

The android app works and the iso app crashes with the exception below.

I haven't included references and version detail (other than the Android and Kotlin version above) as I assume that you can find it from the commit. Let me know if you need more information.

[Note that I removed some of the file system path information from the exception in a lame attempt to obfuscate some of the possibly personal data - I hope that doesn't confused the issue]

/xxx/AndroidStudioProjects/kmm-networking-and-data-storage/build/ios/Debug-iphonesimulator/iosApp.app
2022-07-12 12:05:26.685267-0400 iosApp[8420:340254] [LayoutConstraints] Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want. 
    Try this: 
        (1) look at each constraint and try to figure out which you don't expect; 
        (2) find the code that added the unwanted constraint or constraints and fix it. 
(
    "<NSLayoutConstraint:0x6000004d5d60 'BIB_Leading_Leading' H:|-(0)-[_UIModernBarButton:0x13a01a150]   (active, names: '|':_UIButtonBarButton:0x13a016f80 )>",
    "<NSLayoutConstraint:0x6000004f7d40 'UINav_static_button_horiz_position' _UIModernBarButton:0x13a01a150.leading == UILayoutGuide:0x600001ef1340'UIViewLayoutMarginsGuide'.leading   (active)>",
    "<NSLayoutConstraint:0x6000004f7d90 'UINavItemContentGuide-leading' H:[_UIButtonBarButton:0x13a016f80]-(6)-[UILayoutGuide:0x600001ef1260'UINavigationBarItemContentLayoutGuide']   (active)>",
    "<NSLayoutConstraint:0x6000004fd630 'UINavItemContentGuide-trailing' UILayoutGuide:0x600001ef1260'UINavigationBarItemContentLayoutGuide'.trailing == _UINavigationBarContentView:0x13a20e820.trailing   (active)>",
    "<NSLayoutConstraint:0x6000004fb930 'UIView-Encapsulated-Layout-Width' _UINavigationBarContentView:0x13a20e820.width == 0   (active)>",
    "<NSLayoutConstraint:0x6000004fd2c0 'UIView-leftMargin-guide-constraint' H:|-(8)-[UILayoutGuide:0x600001ef1340'UIViewLayoutMarginsGuide'](LTR)   (active, names: '|':_UINavigationBarContentView:0x13a20e820 )>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x6000004d5d60 'BIB_Leading_Leading' H:|-(0)-[_UIModernBarButton:0x13a01a150]   (active, names: '|':_UIButtonBarButton:0x13a016f80 )>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.
2022-07-12 12:05:26.686456-0400 iosApp[8420:340254] [LayoutConstraints] Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want. 
    Try this: 
        (1) look at each constraint and try to figure out which you don't expect; 
        (2) find the code that added the unwanted constraint or constraints and fix it. 
(
    "<NSLayoutConstraint:0x6000004d5270 UIView:0x137712610.trailing == _UIBackButtonMaskView:0x137710e70.trailing   (active)>",
    "<NSLayoutConstraint:0x6000004d63a0 'Mask_Trailing_Trailing' _UIBackButtonMaskView:0x137710e70.trailing == _UIButtonBarButton:0x13a016f80.trailing   (active)>",
    "<NSLayoutConstraint:0x6000004d64e0 'MaskEV_Leading_BIB_Trailing' H:[_UIModernBarButton:0x13a01a150]-(0)-[UIView:0x137712610]   (active)>",
    "<NSLayoutConstraint:0x6000004f7d40 'UINav_static_button_horiz_position' _UIModernBarButton:0x13a01a150.leading == UILayoutGuide:0x600001ef1340'UIViewLayoutMarginsGuide'.leading   (active)>",
    "<NSLayoutConstraint:0x6000004f7d90 'UINavItemContentGuide-leading' H:[_UIButtonBarButton:0x13a016f80]-(6)-[UILayoutGuide:0x600001ef1260'UINavigationBarItemContentLayoutGuide']   (active)>",
    "<NSLayoutConstraint:0x6000004fd630 'UINavItemContentGuide-trailing' UILayoutGuide:0x600001ef1260'UINavigationBarItemContentLayoutGuide'.trailing == _UINavigationBarContentView:0x13a20e820.trailing   (active)>",
    "<NSLayoutConstraint:0x6000004fb930 'UIView-Encapsulated-Layout-Width' _UINavigationBarContentView:0x13a20e820.width == 0   (active)>",
    "<NSLayoutConstraint:0x6000004fd2c0 'UIView-leftMargin-guide-constraint' H:|-(8)-[UILayoutGuide:0x600001ef1340'UIViewLayoutMarginsGuide'](LTR)   (active, names: '|':_UINavigationBarContentView:0x13a20e820 )>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x6000004d5270 UIView:0x137712610.trailing == _UIBackButtonMaskView:0x137710e70.trailing   (active)>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.
2022-07-12 12:05:26.689307-0400 iosApp[8420:340254] [LayoutConstraints] Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want. 
    Try this: 
        (1) look at each constraint and try to figure out which you don't expect; 
        (2) find the code that added the unwanted constraint or constraints and fix it. 
(
    "<NSLayoutConstraint:0x6000004d5db0 'BIB_Trailing_CB_Leading' H:[_UIModernBarButton:0x13a01a150]-(6)-[_UIModernBarButton:0x13a018230'SpaceX Launches']   (active)>",
    "<NSLayoutConstraint:0x6000004d5e00 'CB_Trailing_Trailing' _UIModernBarButton:0x13a018230'SpaceX Launches'.trailing <= _UIButtonBarButton:0x13a016f80.trailing   (active)>",
    "<NSLayoutConstraint:0x6000004f7d40 'UINav_static_button_horiz_position' _UIModernBarButton:0x13a01a150.leading == UILayoutGuide:0x600001ef1340'UIViewLayoutMarginsGuide'.leading   (active)>",
    "<NSLayoutConstraint:0x6000004f7d90 'UINavItemContentGuide-leading' H:[_UIButtonBarButton:0x13a016f80]-(6)-[UILayoutGuide:0x600001ef1260'UINavigationBarItemContentLayoutGuide']   (active)>",
    "<NSLayoutConstraint:0x6000004fd630 'UINavItemContentGuide-trailing' UILayoutGuide:0x600001ef1260'UINavigationBarItemContentLayoutGuide'.trailing == _UINavigationBarContentView:0x13a20e820.trailing   (active)>",
    "<NSLayoutConstraint:0x6000004fb930 'UIView-Encapsulated-Layout-Width' _UINavigationBarContentView:0x13a20e820.width == 0   (active)>",
    "<NSLayoutConstraint:0x6000004fd2c0 'UIView-leftMargin-guide-constraint' H:|-(8)-[UILayoutGuide:0x600001ef1340'UIViewLayoutMarginsGuide'](LTR)   (active, names: '|':_UINavigationBarContentView:0x13a20e820 )>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x6000004d5db0 'BIB_Trailing_CB_Leading' H:[_UIModernBarButton:0x13a01a150]-(6)-[_UIModernBarButton:0x13a018230'SpaceX Launches']   (active)>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.
Uncaught Kotlin exception: kotlin.native.IncorrectDereferenceException: illegal attempt to access non-shared <object>@27deba8 from other thread
    at 0   shared                              0x101211a43        kfun:kotlin.Throwable#<init>(kotlin.String?){} + 95 (/opt/buildAgent/work/c3a91df21e46e2c8/kotlin/kotlin-native/runtime/src/main/kotlin/kotlin/Throwable.kt:24:37)
    at 1   shared                              0x10120b047        kfun:kotlin.Exception#<init>(kotlin.String?){} + 91 (/opt/buildAgent/work/c3a91df21e46e2c8/kotlin/kotlin-native/runtime/src/main/kotlin/kotlin/Exceptions.kt:23:44)
    at 2   shared                              0x10120b27b        kfun:kotlin.RuntimeException#<init>(kotlin.String?){} + 91 (/opt/buildAgent/work/c3a91df21e46e2c8/kotlin/kotlin-native/runtime/src/main/kotlin/kotlin/Exceptions.kt:34:44)
    at 3   shared                              0x10121d73f        kfun:kotlin.native.IncorrectDereferenceException#<init>(kotlin.String){} + 91 (/opt/buildAgent/work/c3a91df21e46e2c8/kotlin/kotlin-native/runtime/src/main/kotlin/kotlin/native/Runtime.kt:34:36)
    at 4   shared                              0x10122041f        ThrowIllegalObjectSharingException + 423 (/opt/buildAgent/work/c3a91df21e46e2c8/kotlin/kotlin-native/runtime/src/main/kotlin/kotlin/native/concurrent/Internal.kt:115:11)
    at 5   shared                              0x10135e3a3        _ZN12_GLOBAL__N_128throwIllegalSharingExceptionEP9ObjHeader + 27 
    at 6   shared                              0x10135f97b        _ZN12_GLOBAL__N_136terminateWithIllegalSharingExceptionEP9ObjHeader + 11 
    at 7   shared                              0x10135fb2b        _ZNK27BackRefFromAssociatedObject3refIL11ErrorPolicy3EEEP9ObjHeaderv + 231 
    at 8   shared                              0x10135ebef        _ZN12_GLOBAL__N_111toKotlinImpEP11objc_objectP13objc_selectorPP9ObjHeader + 51 
    at 9   shared                              0x101355427        Kotlin_Interop_refFromObjC + 111 
    at 10  shared                              0x1015612af        _696f2e6b746f723a6b746f722d636c69656e742d64617277696e_knbridge160 + 207 (/xxx/Documents/agent/work/8d547b974a7be21f/ktor-client/ktor-client-darwin/darwin/src/io/ktor/client/engine/darwin/internal/DarwinResponseReader.kt:63:14)
    at 11  shared                              0x10156a9ff        _696f2e6b746f723a6b746f722d636c69656e742d64617277696e_kncfun162 + 79 
    at 12  CFNetwork                           0x183c22beb        _CFHostIsDomainTopLevelForCertificatePolicy + 13587 
    at 13  Foundation                          0x1807ec16f        __NSBLOCKOPERATION_IS_CALLING_OUT_TO_A_BLOCK__ + 15 
    at 14  Foundation                          0x1807ec04b        -[NSBlockOperation main] + 99 
    at 15  Foundation                          0x1807ef16f        __NSOPERATION_IS_INVOKING_MAIN__ + 19 
    at 16  Foundation                          0x1807eb1cf        -[NSOperation start] + 759 
    at 17  Foundation                          0x1807efb07        __NSOPERATIONQUEUE_IS_STARTING_AN_OPERATION__ + 19 
    at 18  Foundation                          0x1807ef60f        __NSOQSchedule_f + 179 
    at 19  libdispatch.dylib                   0x18011cca3        _dispatch_block_async_invoke2 + 103 
    at 20  libdispatch.dylib                   0x18010ea97        _dispatch_client_callout + 15 
    at 21  libdispatch.dylib                   0x180111bff        _dispatch_continuation_pop + 447 
    at 22  libdispatch.dylib                   0x180111323        _dispatch_async_redirect_invoke + 667 
    at 23  libdispatch.dylib                   0x18011f773        _dispatch_root_queue_drain + 431 
    at 24  libdispatch.dylib                   0x1801200f3        _dispatch_worker_thread2 + 159 
    at 25  libsystem_pthread.dylib             0x1cc0adb03        _pthread_wqthread + 223 
    at 26  libsystem_pthread.dylib             0x1cc0ac903        start_wqthread + 7 

Process finished with exit code 0
jkbredsquiggles commented 2 years ago

Answering my own question - I looked at one of the ktor kmm demos and noticed that the memory model needs to be specified in the gradle.properties file, i.e. I added this:

# ios
kotlin.native.binary.memoryModel=experimental

and the problems went away.

jkbredsquiggles commented 2 years ago

As an aside - related to my issues with my initial attempts using the current version - I also noticed that the ktor example at the above link treated the html response as a string instead of using the ContentNegotiation (feature?), e.g.

it used something like

suspend fun getHtml(): String {
        val response = client.get("https://ktor.io/docs")
        return response.bodyAsText()
    }

instead of

suspend fun getAllLaunches(): List<RocketLaunch> {
        return httpClient.get("https://api.spacexdata.com/v3/launches").body()
    }

I'm hoping the ktor demo works. Treating the body as text and manually applying Json serialization was going to be my next attempt at addressing my issues - if whomever is dealing with this has the time to confirm whether that second issue can be addressed in a similar manner it would be appreciated and it might help make this application work better with the current version of kotlin and ktor.

jkbredsquiggles commented 2 years ago

I'm leaving the issue open, as I think the demo needs to be updated. But I'd also like to assume that I've helped solve it.

Venkat-juju commented 2 years ago

This worked for me... thanks..

pahill commented 1 year ago

Answering my own question - I looked at one of the ktor kmm demos and noticed that the memory model needs to be specified in the gradle.properties file, i.e. I added this:

# ios
kotlin.native.binary.memoryModel=experimental

and the problems went away.

Thank you for helping! You're a star!