ebtokyo
12/05/2025, 11:28 AMpainterResource(Res.drawable.test).
Now if I do Res.getUri("files/test.txt") or Res.readBytes("files/test.txt") I'm getting this error:
java.lang.IllegalStateException: Android context is not initialized. If it happens in the Preview mode then call PreviewContextConfigurationEffect() function.
Is it a limitation from compose resources, no file loading from common code?Michael Paus
12/05/2025, 12:31 PMebtokyo
12/05/2025, 12:38 PMebtokyo
12/05/2025, 12:46 PM@OptIn(ExperimentalResourceApi::class)
@Preview
@Composable
fun MyPreview() {
Column(modifier = Modifier.fillMaxWidth()) {
val resourceReader = LocalResourceReader.current
val bytes = remember {
runBlocking {
resourceReader.read("files/test.txt")
// Will throw java.lang.IllegalStateException: Android context is not initialized. If it
// happens in the Preview mode then call PreviewContextConfigurationEffect() function.
}
}
Image(
// Works fine, resource load so somehow file is able to load. painterResource also uses LocalResourceReader?
painter = painterResource(Res.drawable.test),
contentDescription = "",
)
}
}Michael Paus
12/05/2025, 1:05 PMebtokyo
12/05/2025, 1:12 PMPreviewContextConfigurationEffect() isn't available in commonMain? Only in androidMain.ebtokyo
12/05/2025, 3:26 PM