I'm just getting started developing Kotlin MP. I'm on the 4th step of the getting started tutorial:...
a
I'm just getting started developing Kotlin MP. I'm on the 4th step of the getting started tutorial: https://kotlinlang.org/docs/multiplatform-mobile-upgrade-app.html Android app runs fine, but the iOS app crashes with:
Copy code
/Users/abarsky/AndroidStudioProjects/KotlinMultiplatformSandbox/build/ios/Debug-iphonesimulator/iosApp.app
Uncaught Kotlin exception: kotlin.native.IncorrectDereferenceException: illegal attempt to access non-shared <object>@3d723a8 from other thread
    at 0   shared                              0x10375ea73        kfun:kotlin.Throwable#<init>(kotlin.String?){} + 95 
    at 1   shared                              0x103757f93        kfun:kotlin.Exception#<init>(kotlin.String?){} + 91 
    at 2   shared                              0x1037581c7        kfun:kotlin.RuntimeException#<init>(kotlin.String?){} + 91 
    at 3   shared                              0x10376a393        kfun:kotlin.native.IncorrectDereferenceException#<init>(kotlin.String){} + 91 
    at 4   shared                              0x10376ce9b        ThrowIllegalObjectSharingException + 415 
    at 5   shared                              0x103b0a02f        _ZN12_GLOBAL__N_128throwIllegalSharingExceptionEP9ObjHeader + 27 
    at 6   shared                              0x103b0b5f7        _ZN12_GLOBAL__N_136terminateWithIllegalSharingExceptionEP9ObjHeader + 11 
    at 7   shared                              0x103b0b7a7        _ZNK27BackRefFromAssociatedObject3refIL11ErrorPolicy3EEEP9ObjHeaderv + 231 
    at 8   shared                              0x103b0a837        _ZN12_GLOBAL__N_111toKotlinImpEP11objc_objectP13objc_selectorPP9ObjHeader + 51 
    at 9   shared                              0x103b011ab        Kotlin_Interop_refFromObjC + 111 
    at 10  shared                              0x1039e2cbb        _696f2e6b746f723a6b746f722d636c69656e742d64617277696e_knbridge101 + 207 
    at 11  shared                              0x103acb7cb        _696f2e6b746f723a6b746f722d636c69656e742d64617277696e_kncfun103 + 79 
    at 12  CFNetwork                           0x1049e37cf        /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/CFNetwork.framework/CFNetwork + 47055 
    at 13  Foundation                          0x105e4f8d7        __NSBLOCKOPERATION_IS_CALLING_OUT_TO_A_BLOCK__ + 15 
    at 14  Foundation                          0x105e4f7cb        -[NSBlockOperation main] + 99 
    at 15  Foundation                          0x105e524f3        __NSOPERATION_IS_INVOKING_MAIN__ + 11
as the httpClient line is executed
Copy code
@Throws(Exception::class)
    suspend fun greeting(): String {
        val rockets: List<RocketLaunch> =
            httpClient.get("<https://api.spacexdata.com/v4/launches>").body()
Here are my plugin versions
Copy code
plugins {
    //trick: for the same plugin versions in all sub-modules
    id("com.android.application").version("7.3.1").apply(false)
    id("com.android.library").version("7.3.1").apply(false)
    kotlin("android").version("1.7.10").apply(false)
    kotlin("multiplatform").version("1.7.10").apply(false)
}
which were setup automatically for me when I made a new Kotlin Multiplatform App from within Android studio. https://kotlinlang.org/docs/multiplatform-mobile-create-first-app.html Running XCode 14.. Is there a complete project I can download to make sure it's not a mistake typing in the tutorial code?
h
I guess it is a bug in the template. It should work out of the box with kotlin 1.7.20: https://kotlinlang.slack.com/archives/C3PQML5NU/p1670483975388369 Reason: Ktor 2 uses the new memory model. You can enable it explicitly or use 1.7.20 which uses the new MM by default.
a
Changing the kotlin android and multiplatform version from
1.7.10
to
1.7.20
fixed it. Thanks.