WojciechOsak / Calendar

Kotlin Multiplatform Calendar Library
Apache License 2.0
98 stars 5 forks source link

IOS 17.5 BUILD FAILURE with Failed to load native library:libjansi.jnilib. #14

Open kopoh opened 1 month ago

kopoh commented 1 month ago

I use kotlin 2.0.0 (+ tested on 1.9.23 same error), compose multiplatform 1.6.10, and last version of calendar 1.0.1

On android, desktop and js all working pretty fine

All error code

Task :composeApp:linkDebugFrameworkIosSimulatorArm64 Failed to load native library:libjansi.jnilib. The native library file at /user/.gradle/native/jansi/1.18/osx/libjansi.jnilib is not executable, make sure that the directory is mounted on a partition without the noexec flag, or set the jansi.tmpdir system property to point to a proper location. osinfo: Mac/arm64 java.lang.UnsatisfiedLinkError: Can't load library: /user/.gradle/native/jansi/1.18/osx/libjansi.jnilib error: Compilation failed: Exception during generating code for following declaration: Inside: FILE fqName:com.KopohGames.Scheduler.ui.Schedule fileName:/repo/composeApp/src/commonMain/kotlin/com/KopohGames/Scheduler/ui/Schedule/ScheduleScreen.kt Inside: CLASS CLASS name:ScheduleScreen modality:FINAL visibility:public superTypes:[cafe.adriel.voyager.core.screen.Screen; org.koin.core.component.KoinComponent] Inside: FUN LOCAL_FUNCTION_FOR_LAMBDA name:Content$lambda$53$lambda$38 visibility:private modality:FINAL <> ($daysOfWeek:kotlin.collections.List, state:@[ParameterName(name = "dayState")] io.wojciechosak.calendar.config.DayState, $composer:androidx.compose.runtime.Composer?, $changed:kotlin.Int) returnType:kotlin.Unit Inside: FILE fqName:androidx.compose.foundation.layout fileName:/opt/buildAgent/work/8a20760945d0aeba/compose/foundation/foundation-layout/src/commonMain/kotlin/androidx/compose/foundation/layout/Column.kt Inside: FILE fqName:androidx.compose.ui.layout fileName:/opt/buildAgent/work/8a20760945d0aeba/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/layout/Layout.kt Inside: FILE fqName:androidx.compose.runtime fileName:/opt/buildAgent/work/8a20760945d0aeba/compose/runtime/runtime/src/commonMain/kotlin/androidx/compose/runtime/Composables.kt Inside: FILE fqName:androidx.compose.foundation.layout fileName:/opt/buildAgent/work/8a20760945d0aeba/compose/foundation/foundation-layout/src/commonMain/kotlin/androidx/compose/foundation/layout/Column.kt // FILE: ScheduleScreen.kt // path: /repo/composeApp/src/commonMain/kotlin/com/KopohGames/Scheduler/ui/Schedule/ScheduleScreen.kt package com.KopohGames.Scheduler.ui.Schedule

Through trial and error, I identified a problem in passing the state in the Webview component, because if I copy the DayState exactly, and just redefine the values via

data class TESTDAYState(
    val date: LocalDate,
    val isActiveDay: Boolean = false,
    val isForPreviousMonth: Boolean = false,
    val isForNextMonth: Boolean = false,
    val enabled: Boolean = true
)

val DayState: TESTDAYState = TESTDAYState(
                                state.date,
                                state.isActiveDay,
                                state.isForNextMonth,
                                state.isForPreviousMonth,
                                state.enabled
                            )

This code is from this library repo (I just change data class and colors to MaterialTheme)

@Composable
fun WeekViewDay(
    modifier: Modifier = Modifier,
    state: TESTDAYState,
    onClick: (TESTDAYState) -> Unit = {}
) {
    OutlinedButton(
        onClick = { onClick(state) },
        modifier = modifier,
        shape = RoundedCornerShape(50.dp),
        border = BorderStroke(1.dp, Color.Transparent),
        contentPadding = PaddingValues(0.dp),
        interactionSource = MutableInteractionSource(),
        enabled = state.enabled,
        colors =
        ButtonDefaults.outlinedButtonColors(
            contentColor =
            if (state.isForPreviousMonth || state.isForNextMonth) {
                MaterialTheme.colorScheme.tertiary
            } else {
                if (state.isActiveDay) MaterialTheme.colorScheme.primary else MaterialTheme.colorScheme.onTertiary
            },
        ),
    ) {
        Column(horizontalAlignment = Alignment.CenterHorizontally) {
            Text(
                "${state.date.dayOfMonth}",
                fontSize = 20.sp,
                textAlign = TextAlign.Center,
            )
        }
    }
}

To display my weekview I use example from docs

WeekView { state ->
                            val DayState: TESTDAYState = TESTDAYState(
                                state.date,
                                state.isActiveDay,
                                state.isForNextMonth,
                                state.isForPreviousMonth,
                                state.enabled
                            )
                            Column(horizontalAlignment = Alignment.CenterHorizontally) {
                                Text(daysOfWeek[state.date.dayOfWeek.isoDayNumber - 1])
                                WeekViewDay(
                                    state = DayState,
                                    modifier = Modifier.width(58.dp)
                                )
                            }
                        } 

Then everything starts to build, but the choice of the day and its background do not work (with this it is clear, the values are simply not returned back to the function above)

https://github.com/user-attachments/assets/6b502f11-1549-4340-8178-1e03b4b8b6c8

kopoh commented 1 month ago

I looked at the source code

@OptIn(markerClass = {androidx. compose. foundation. ExperimentalFoundationApi::class})
@Composable
public fun WeekView(
    startDate: LocalDate = Clock.System. now()             .toLocalDateTime(TimeZone. currentSystemDefault())             .toLocalDate(),
    minDate: LocalDate = startDate.copy(day = 1).minus(3, DateTimeUnit. MONTH),
    maxDate: LocalDate = startDate.copy(day = monthLength(startDate. month, startDate. year))             .plus(3, DateTimeUnit. MONTH),
    daysOffset: Int = 0,
    showDaysBesideRange: Boolean = true,
    calendarAnimator: CalendarAnimator = CalendarAnimator(startDate),
    isActive: (LocalDate) -> Boolean = {         val today =             Clock. System. now().toLocalDateTime(TimeZone. currentSystemDefault()).toLocalDate()         today == it     },
    modifier: Modifier = Modifier,
    firstVisibleDate: (LocalDate) -> Unit = {},
    day: @Composable (dayState: DayState) -> Unit = { state ->         weekDay(state) {             CalendarDay(                 state,                 modifier = Modifier. width(58.dp),             )         }     }
): Unit

It seems that the problem with state is in this place

day: @Composable (dayState: DayState) -> Unit = { state ->  weekDay(state) { CalendarDay( state,  modifier = Modifier. width(58.dp), ) }
kopoh commented 4 weeks ago

I found root of problems. It's Kotlin 2.0 bug. You can track it here https://youtrack.jetbrains.com/issue/CMP-4809. Now, you can fix it by adding the following lines to your gradle.properties file:

kotlin.native.cacheKind=none
compose.kotlin.native.manageCacheKind=false