Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
kopoh opened this issue Jul 11, 2024 · 2 comments
Open

Comments

@kopoh
Copy link

kopoh commented Jul 11, 2024

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<kotlin.String>, 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)

Simulator.Screen.Recording.-.iPhone.15.Plus.-.2024-07-11.at.22.07.13.mp4
@kopoh
Copy link
Author

kopoh commented Jul 11, 2024

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
Copy link
Author

kopoh commented Jul 29, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant