Encountering 'Exception during IR lowering' error with Jetpack Compose clickable modifier in custom Checkbox

I’m stuck with a weird problem in my Android app. I made a custom Checkbox inside a Surface. It’s got a clickable modifier, but when I try to build it, I get this error: ‘Exception during IR lowering’.

Here’s a simplified version of my code:

MyCustomSurface(
    modifier = Modifier.clickable(
        enabled = isEnabled,
        interactionSource = myInteractionSource,
        indication = myRippleEffect(),
        role = Role.Checkbox,
        onClick = { toggleCheckbox() }
    )
) {
    RowContent {
        CustomCheckbox(isChecked = isChecked)
        CustomText(content = labelText)
    }
}

The build works fine if I take out the clickable modifier. I’ve tried changing some version numbers, but no luck. Right now I’m using Kotlin 1.5.30 and Compose 1.0.2.

Any ideas on how to fix this? It’s driving me crazy!

hm, that’s a tricky one! have u tried wrapping ur clickable modifier in a Modifier.composed{}? sometimes that helps with weird compiler issues. also, maybe try updating to the latest compose version? they fix bugs pretty often. what happens if u use a simple Box instead of MyCustomSurface? just brainstorming here :thinking:

yo, that error sounds annoying af. tried clearing ur build cache? sometimes that fixes weird stuff. also, maybe ditch the custom surface for now and use a basic composable like Column. could be some weird interaction goin on. if nothin works, try posting ur full code somewhere, might help spot the issue.

I encountered a similar issue recently. The problem might be related to how the custom Surface is implemented. Try moving the clickable modifier to the RowContent instead:

MyCustomSurface {
    RowContent(
        modifier = Modifier.clickable(
            enabled = isEnabled,
            interactionSource = myInteractionSource,
            indication = myRippleEffect(),
            role = Role.Checkbox,
            onClick = { toggleCheckbox() }
        )
    ) {
        CustomCheckbox(isChecked = isChecked)
        CustomText(content = labelText)
    }
}

This approach often resolves IR lowering exceptions by simplifying the composition structure. If the issue persists, consider reviewing the implementation of MyCustomSurface for any potential conflicts with the clickable modifier.