I really have a hard time with the new resource ha...
# compose-desktop
m
I really have a hard time with the new resource handling in 1.6.0-beta01. I just introduced a method to provide the app-icon for the window in the Main method.
Copy code
@OptIn(ExperimentalResourceApi::class)
@Composable
fun appIconPainter(): Painter {
    val painter1 = org.jetbrains.compose.resources.painterResource(Res.drawable.appicon)
    val painter2 = androidx.compose.ui.res.painterResource("drawable/appIcon.svg")
    return painter2
}
Calling this method results in an exception during the creation of painter1.
Copy code
Exception in thread "main" java.lang.IllegalArgumentException: Failed to Image::makeFromEncoded
	at org.jetbrains.skia.Image$Companion.makeFromEncoded(Image.kt:137)
	at org.jetbrains.compose.resources.ImageResources_skikoKt.toImageBitmap(ImageResources.skiko.kt:8)
	at org.jetbrains.compose.resources.ImageResourcesKt$imageResource$imageBitmap$3$cached$1.invoke(ImageResources.kt:77)
	at org.jetbrains.compose.resources.ImageResourcesKt$imageResource$imageBitmap$3$cached$1.invoke(ImageResources.kt:76)
	at org.jetbrains.compose.resources.ImageResourcesKt$loadImage$2$deferred$1$1$1.invokeSuspend(ImageResources.kt:134)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:108)
	at kotlinx.coroutines.EventLoopImplBase.processNextEvent(EventLoop.common.kt:281)
	at kotlinx.coroutines.BlockingCoroutine.joinBlocking(Builders.kt:85)
	at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking(Builders.kt:59)
	at kotlinx.coroutines.BuildersKt.runBlocking(Unknown Source)
	at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking$default(Builders.kt:38)
	at kotlinx.coroutines.BuildersKt.runBlocking$default(Unknown Source)
	at org.jetbrains.compose.resources.ResourceState_blockingKt.rememberResourceState(ResourceState.blocking.kt:15)
	at org.jetbrains.compose.resources.ImageResourcesKt.imageResource(ImageResources.kt:74)
	at org.jetbrains.compose.resources.ImageResourcesKt.painterResource(ImageResources.kt:58)
	at ModelBridgeImpl.appIconPainter(main.desktop.kt:139)
However, if I just comment out the offending line for painter1 the code works as expected. It seems that the jetbrains variant of painterResource does not like SVGs. The resources are located as seen in the screenshot and I can access the other PNG file without problem.
k
yes. SVGs are not supported in common code. use an android vector XML instead
👍🏻 1
I've thought that svg doesn't work on the android 🤔
m
This is a desktop application and the
androidx
variant of painterResource has always supported SVGs. Why is the Jetbrains resource handling more picky?
k
because we should support all platforms in the same state
z
Please keep long code snippets and stack traces to the thread in the future