Getting crashes when using DatePicker component on...
# multiplatform
j
Getting crashes when using DatePicker component on iOS with kotlinx datetime. I'm using Kotlin 2.2.20, CMP 1.9.0-rc02 and kotlinx.datetime 0.7.1.
Copy code
Uncaught Kotlin exception: kotlin.native.internal.IrLinkageError: Can not get instance of singleton 'System': No class found for symbol 'kotlinx.datetime/Clock.System|null[0]'
More in 🧵
Getting the following error:
Copy code
Uncaught Kotlin exception: kotlin.native.internal.IrLinkageError: Can not get instance of singleton 'System': No class found for symbol 'kotlinx.datetime/Clock.System|null[0]'
    at 0   myapp.debug.dylib          0x10a6a3beb        kfun:kotlin.native.internal#ThrowIrLinkageError(kotlin.String?){}kotlin.Nothing + 111 
    at 1   myapp.debug.dylib          0x10b4d9797        kfun:androidx.compose.material3.internal.KotlinxDatetimeCalendarModel#<get-today>(){}androidx.compose.material3.internal.CalendarDate + 91 
    at 2   myapp.debug.dylib          0x10b23e107        kfun:androidx.compose.material3.DatePickerStateImpl.<init>#internal + 631 
    at 3   myapp.debug.dylib          0x10b26ef77        kfun:androidx.compose.material3.rememberDatePickerState$$inlined$cache$1.invoke#internal + 259 
    at 4   myapp.debug.dylib          0x10aa8b0ff        kfun:androidx.compose.runtime.saveable#rememberSaveable(kotlin.Array<out|kotlin.Any?>...;androidx.compose.runtime.saveable.Saver<0:0,out|kotlin.Any>?;kotlin.String?;kotlin.Function0<0:0>;androidx.compose.runtime.Composer?;kotlin.Int;kotlin.Int){0§<kotlin.Any>}0:0 + 1859 
    at 5   myapp.debug.dylib          0x10b233287        kfun:androidx.compose.material3#rememberDatePickerState(kotlin.Long?;kotlin.Long?;kotlin.ranges.IntRange?;androidx.compose.material3.DisplayMode;androidx.compose.material3.SelectableDates?;androidx.compose.runtime.Composer?;kotlin.Int;kotlin.Int){}androidx.compose.material3.DatePickerState + 3651 
    at 6   myapp.debug.dylib          0x10be3ba9b        kfun:com.myapp.core.presentation.common.components#SCDatePicker(kotlin.Boolean;kotlin.Function1<kotlin.Boolean,kotlin.Unit>;kotlin.Function1<kotlinx.datetime.LocalDate,kotlin.Unit>;androidx.compose.runtime.Composer?;kotlin.Int){} + 1219 
    at 7   myapp.debug.dylib          0x10bf20e93        kfun:com.myapp.core.presentation.nutritiondiary#NutritionDiaryScreen(com.myapp.core.presentation.nutritiondiary.NutritionDiaryViewModel?;kotlin.Function1<com.myapp.nutrition.models.MealCategoryType,kotlin.Unit>;kotlin.Function3<com.myapp.nutrition.models.DashboardMeal,com.myapp.nutrition.models.MealCategoryType,kotlinx.datetime.LocalDate,kotlin.Unit>;androidx.compose.runtime.Composer?;kotlin.Int;kotlin.Int){} + 6759 
    at 8   myapp.debug.dylib          0x10bc6e527        kfun:com.myapp.core.presentation.HomeLayout$3.$<bridge-DNNNU>invoke(androidx.compose.foundation.layout.PaddingValues;androidx.compose.runtime.Composer;kotlin.Int){}#internal + 5171 
    at 9   myapp.debug.dylib          0x10a8fd3cf        kfun:androidx.compose.runtime.internal.ComposableLambdaImpl#invoke(kotlin.Any?;androidx.compose.runtime.Composer;kotlin.Int){}kotlin.Any? + 1211 
    at 10  myapp.debug.dylib          0x10a909693        kfun:androidx.compose.runtime.internal.ComposableLambdaImpl.ComposableLambdaImpl$invoke$1.$<bridge-DNNU>invoke(androidx.compose.runtime.Composer;kotlin.Int){}#internal + 215 
    at 11  myapp.debug.dylib          0x10a8446b3        kfun:androidx.compose.runtime.ComposerImpl.recomposeToGroupEnd#internal + 3739 
    at 12  myapp.debug.dylib          0x10a846cb7        kfun:androidx.compose.runtime.ComposerImpl#skipCurrentGroup(){} + 831 
    at 13  myapp.debug.dylib          0x10a84e19f        kfun:androidx.compose.runtime.ComposerImpl.doCompose#internal + 2611 
    at 14  myapp.debug.dylib          0x10a863a17        kfun:androidx.compose.runtime.CompositionImpl#recompose(){}kotlin.Boolean + 1043 
    at 15  myapp.debug.dylib          0x10a888b87        kfun:androidx.compose.runtime.Recomposer.performRecompose#internal + 1983 
    at 16  myapp.debug.dylib          0x10a895a4f        kfun:androidx.compose.runtime.Recomposer.Recomposer$runRecomposeAndApplyChanges$2.Recomposer$runRecomposeAndApplyChanges$2$invoke$2.$<bridge-DNU>invoke(kotlin.Long){}#internal + 1867 
    at 17  myapp.debug.dylib          0x10a83339f        kfun:androidx.compose.runtime.BroadcastFrameClock#sendFrame(kotlin.Long){} + 851 
    at 18  myapp.debug.dylib          0x10acbdaaf        kfun:androidx.compose.ui.scene.BaseComposeScene#render(androidx.compose.ui.graphics.Canvas;kotlin.Long){} + 975 
    at 19  myapp.debug.dylib          0x10ad731b7        kfun:androidx.compose.ui.scene.ComposeSceneMediator#render(androidx.compose.ui.graphics.Canvas;kotlin.Long){} + 303 
    at 20  myapp.debug.dylib          0x10ad6836b        kfun:androidx.compose.ui.scene.ComposeHostingViewController.ComposeHostingViewController$viewControllerDidEnterWindowHierarchy$metalView$2.$<bridge-DNNU>invoke(org.jetbrains.skia.Canvas;kotlin.Long){}#internal + 291 
    at 21  myapp.debug.dylib          0x10add4a2b        kfun:androidx.compose.ui.window.MetalView.MetalView$1.$<bridge-DNNU>invoke(org.jetbrains.skia.Canvas;kotlin.Double){}#internal + 495 
    at 22  myapp.debug.dylib          0x10adc6b43        kfun:androidx.compose.ui.window.MetalRedrawer.draw#internal + 3271 
    at 23  myapp.debug.dylib          0x10adca0db        kfun:androidx.compose.ui.window.MetalRedrawer.MetalRedrawer$2.$<bridge-DN>invoke(){}#internal + 519 
    at 24  myapp.debug.dylib          0x10adceca3        kfun:androidx.compose.ui.window.DisplayLinkProxy.$imp:handleDisplayLinkTick#internal + 427 
    at 25  QuartzCore                          0x18f9932a3        <redacted> + 47 
    at 26  QuartzCore                          0x18f970a6f        <redacted> + 875 
    at 27  QuartzCore                          0x18f9841c3        <redacted> + 359 
    at 28  UIKitCore                           0x194888ee7        <redacted> + 127 
    at 29  UIKitCore                           0x194888377        <redacted> + 59 
    at 30  UpdateCycle                         0x2795395f7        <redacted> + 83 
    at 31  CoreFoundation                      0x18ef7f22f        <redacted> + 27 
    at 32  CoreFoundation                      0x18ef7f1a3        <redacted> + 171 
    at 33  CoreFoundation                      0x18ef5cc6b        <redacted> + 231 
    at 34  CoreFoundation                      0x18ef328af        <redacted> + 819 
    at 35  CoreFoundation                      0x18ef31c43        <redacted> + 531 
    at 36  GraphicsServices                    0x22e326497        GSEventRunModal + 119 
    at 37  UIKitCore                           0x1948acddb        <redacted> + 791 
    at 38  UIKitCore                           0x194851b0b        UIApplicationMain + 335 
    at 39  SwiftUI                             0x197a066ef        <redacted> + 167 
    at 40  SwiftUI                             0x197a0322b        <redacted> + 111 
    at 41  SwiftUI                             0x197a02d17        $s7SwiftUI3AppPAAE4mainyyFZ + 171 
    at 42  myapp.debug.dylib          0x10a525cdb        $s14myapp6iOSAppV5$mainyyFZ + 39 
    at 43  myapp.debug.dylib          0x10a525d87        __debug_main_executable_dylib_entry_point + 11 
    at 44  dyld                                0x18bfaae27        <redacted> + 7115 
    Suppressed: kotlinx.coroutines.internal.DiagnosticCoroutineContextException: [androidx.compose.ui.scene.MotionDurationScaleImpl@5704b80, androidx.compose.runtime.BroadcastFrameClock@8708468, StandaloneCoroutine{Cancelling}@56e5c48, FlushCoroutineDispatcher@5990708]
        at 0   myapp.debug.dylib          0x10a781523        kfun:kotlinx.coroutines#handleCoroutineException(kotlin.coroutines.CoroutineContext;kotlin.Throwable){} + 2535 
        at 1   myapp.debug.dylib          0x10a777acb        kfun:kotlinx.coroutines.StandaloneCoroutine.handleJobException#internal + 31 
        at 2   myapp.debug.dylib          0x10a78c80b        kfun:kotlinx.coroutines.JobSupport.finalizeFinishingState#internal + 3203 
        at 3   myapp.debug.dylib          0x10a7924a7        kfun:kotlinx.coroutines.JobSupport.tryMakeCompleting#internal + 1239 
        at 4   myapp.debug.dylib          0x10a791e57        kfun:kotlinx.coroutines.JobSupport#makeCompletingOnce(kotlin.Any?){}kotlin.Any? + 195 
        at 5   myapp.debug.dylib          0x10a774f37        kfun:kotlinx.coroutines.AbstractCoroutine#resumeWith(kotlin.Result<1:0>){} + 135 
        at 6   myapp.debug.dylib          0x10a685357        kfun:kotlin.coroutines.native.internal.BaseContinuationImpl#resumeWith(kotlin.Result<kotlin.Any?>){} + 587 
        at 7   myapp.debug.dylib          0x10a7e9543        kfun:kotlinx.coroutines.UndispatchedCoroutine#afterResume(kotlin.Any?){} + 271 
        at 8   myapp.debug.dylib          0x10a774f93        kfun:kotlinx.coroutines.AbstractCoroutine#resumeWith(kotlin.Result<1:0>){} + 227 
        at 9   myapp.debug.dylib          0x10a685357        kfun:kotlin.coroutines.native.internal.BaseContinuationImpl#resumeWith(kotlin.Result<kotlin.Any?>){} + 587 
        at 10  myapp.debug.dylib          0x10a7d6717        kfun:kotlinx.coroutines.internal.ScopeCoroutine#afterResume(kotlin.Any?){} + 271 
        at 11  myapp.debug.dylib          0x10a774f93        kfun:kotlinx.coroutines.AbstractCoroutine#resumeWith(kotlin.Result<1:0>){} + 227 
        at 12  myapp.debug.dylib          0x10a685357        kfun:kotlin.coroutines.native.internal.BaseContinuationImpl#resumeWith(kotlin.Result<kotlin.Any?>){} + 587 
        at 13  myapp.debug.dylib          0x10a7d1d1f        kfun:kotlinx.coroutines.DispatchedTask#run(){} + 2071 
        at 14  myapp.debug.dylib          0x10acaf07b        kfun:androidx.compose.ui.platform.FlushCoroutineDispatcher.FlushCoroutineDispatcher$dispatch$1.FlushCoroutineDispatcher$dispatch$1$invoke$2.invoke#internal + 603 
        at 15  myapp.debug.dylib          0x10acae80f        kfun:androidx.compose.ui.platform.FlushCoroutineDispatcher.performRun#internal + 163 
        at 16  myapp.debug.dylib          0x10acaedeb        kfun:androidx.compose.ui.platform.FlushCoroutineDispatcher.FlushCoroutineDispatcher$dispatch$1.invoke#internal + 143 
        at 17  myapp.debug.dylib          0x10a686fef        kfun:kotlin.coroutines.intrinsics.createCoroutineUnintercepted$$inlined$createCoroutineFromSuspendFunction$2.invokeSuspend#internal + 531 
        at 18  myapp.debug.dylib          0x10a6851bb        kfun:kotlin.coroutines.native.internal.BaseContinuationImpl#resumeWith(kotlin.Result<kotlin.Any?>){} + 175 
        at 19  myapp.debug.dylib          0x10a7d1b17        kfun:kotlinx.coroutines.DispatchedTask#run(){} + 1551 
        at 20  myapp.debug.dylib          0x10a7f2e07        kfun:kotlinx.coroutines.DarwinMainDispatcher.DarwinMainDispatcher$dispatch$$inlined$autoreleasepool$1.$<bridge-DN>invoke(){}#internal + 183 
        at 21  myapp.debug.dylib          0x10c43ab03        ___6f72672e6a6574627261696e732e6b6f746c696e783a6b6f746c696e782d636f726f7574696e65732d636f72652f6f70742f6275696c644167656e742f776f726b2f343465633665383530643563363366302f6b6f746c696e782d636f726f7574696e65732d636f72652f6e617469766544617277696e2f7372632f44697370617463686572732e6b74_knbridge7_block_invoke + 363 
        at 22  libdispatch.dylib                   0x1055bc63b        _dispatch_call_block_and_release + 31 
        at 23  libdispatch.dylib                   0x1055d62cf        _dispatch_client_callout + 15 
        at 24  libdispatch.dylib                   0x1055f74bf        _dispatch_main_queue_drain.cold.5 + 875 
        at 25  libdispatch.dylib                   0x1055cc777        _dispatch_main_queue_drain + 179 
        at 26  libdispatch.dylib                   0x1055cc6b3        _dispatch_main_queue_callback_4CF + 43 
        at 27  CoreFoundation                      0x18ef8051f        <redacted> + 15 
        at 28  CoreFoundation                      0x18ef32d13        <redacted> + 1943 
        at 29  CoreFoundation                      0x18ef31c43        <redacted> + 531 
        ... and 9 more common stack frames skipped
Stacktrace shows the following: 1. My Datepicker component gets called 2. rememberDatePickerState() gets created 3. it creates DatePickerStateImpl 4. DatePickerStateImpl needs KotlinxDatetimeCalendarModel 5. KotlinxDatetimeCalendarModel tries to access Clock.System 6. Fails, since kotlinx.datetime.Clock.System doesn't exists on iOS This is the content of my component, so nothing special in here:
Copy code
val datePickerState = rememberDatePickerState()
    if (showDatePicker) {
        DatePickerDialog(
            onDismissRequest = {
                onShowDatePicker(false)
            },
            confirmButton = {
                TextButton(
                    onClick = {
                        datePickerState.selectedDateMillis?.let { selectedMillis ->
                            val selectedDate =
                                kotlin.time.Instant.Companion.fromEpochMilliseconds(selectedMillis)
                                    .toLocalDateTime(timeZone = TimeZone.currentSystemDefault()).date
                            onChangeDate(selectedDate)
                        }
                        onShowDatePicker(false)
                    }
                ) {
                    Text(
                        text = stringResource(Res.string.ok),
                        style = MaterialTheme.typography.labelLarge,
                        color = MaterialTheme.colorScheme.primary,
                    )
                }
            },
            dismissButton = {
                TextButton(
                    onClick = {
                        onShowDatePicker(false)
                    }
                ) {
                    Text(
                        text = stringResource(Res.string.cancel),
                        style = MaterialTheme.typography.labelLarge,
                        color = MaterialTheme.colorScheme.primary,
                    )
                }
            },
            shape = ScTheme.Shapes.small,
            colors = DatePickerDefaults.colors(containerColor = MaterialTheme.colorScheme.surface)
        ) {
            DatePicker(
                modifier = Modifier.fillMaxWidth(),
                state = datePickerState,
                colors = DatePickerDefaults.colors(
                    containerColor = MaterialTheme.colorScheme.surface,
                    titleContentColor = MaterialTheme.colorScheme.onSurface,
                    headlineContentColor = MaterialTheme.colorScheme.onSurface,
                    selectedDayContainerColor = MaterialTheme.colorScheme.primary,
                    selectedDayContentColor = MaterialTheme.colorScheme.onPrimary,
                    todayDateBorderColor = MaterialTheme.colorScheme.primary,
                    todayContentColor = MaterialTheme.colorScheme.primary,
                    dayContentColor = MaterialTheme.colorScheme.onSurface,
                    currentYearContentColor = MaterialTheme.colorScheme.onSurface,
                    subheadContentColor = MaterialTheme.colorScheme.onSurface,
                    yearContentColor = MaterialTheme.colorScheme.onSurface,
                    selectedYearContainerColor = MaterialTheme.colorScheme.primary,
                    selectedYearContentColor = MaterialTheme.colorScheme.onPrimary,
                    dayInSelectionRangeContentColor = MaterialTheme.colorScheme.onSurface,
                    weekdayContentColor = MaterialTheme.colorScheme.onSurface,
                    disabledDayContentColor = MaterialTheme.colorScheme.onSurface,
                    disabledSelectedDayContainerColor = MaterialTheme.colorScheme.onSurface,
                    disabledSelectedDayContentColor = MaterialTheme.colorScheme.onSurface,
                    dayInSelectionRangeContainerColor = MaterialTheme.colorScheme.onSurface,
                ),
            )
        }
    }
c
j