JetBrains / compose-multiplatform

Compose Multiplatform, a modern UI framework for Kotlin that makes building performant and beautiful user interfaces easy and enjoyable.
https://jetbrains.com/lp/compose-multiplatform
Apache License 2.0
15.73k stars 1.14k forks source link

Android doesn't support SVG resources #4670

Closed Jafar-Al-Rashid closed 3 months ago

Jafar-Al-Rashid commented 3 months ago

Describe the bug Null pointer exception on using drawable resource on compose multiplatform

                                                                                                java.lang.NullPointerException: decodeByteArray(...) must not be null
                                                                                                    at org.jetbrains.compose.resources.ImageResources_androidKt.toImageBitmap(ImageResources.android.kt:10)
                                                                                                    at org.jetbrains.compose.resources.ImageResourcesKt$imageResource$imageBitmap$3$cached$1.invoke(ImageResources.kt:62)
                                                                                                    at org.jetbrains.compose.resources.ImageResourcesKt$imageResource$imageBitmap$3$cached$1.invoke(ImageResources.kt:61)
                                                                                                    at org.jetbrains.compose.resources.ImageResourcesKt$loadImage$2$deferred$1$1$1.invokeSuspend(ImageResources.kt:140)
                                                                                                    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
                                                                                                    at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:104)
                                                                                                    at kotlinx.coroutines.EventLoopImplBase.processNextEvent(EventLoop.common.kt:277)
                                                                                                    at kotlinx.coroutines.BlockingCoroutine.joinBlocking(Builders.kt:95)
                                                                                                    at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking(Builders.kt:69)
                                                                                                    at kotlinx.coroutines.BuildersKt.runBlocking(Unknown Source:1)
                                                                                                    at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking$default(Builders.kt:48)
                                                                                                    at kotlinx.coroutines.BuildersKt.runBlocking$default(Unknown Source:1)
                                                                                                    at org.jetbrains.compose.resources.ResourceState_blockingKt.rememberResourceState(ResourceState.blocking.kt:30)
                                                                                                    at org.jetbrains.compose.resources.ImageResourcesKt.imageResource(ImageResources.kt:59)

Affected platforms Tested on Android only

Versions

To Reproduce Steps and/or the code snippet to reproduce the behavior:

  1. Try loading an image from kotlin multiplatform resources Image( bitmap = imageResource(Res.drawable.app_icon), contentDescription = "", )

Expected behavior Resource drawables should load with no errors

terrakok commented 3 months ago

What is an extension of the image? Could you provide a sample?

Jafar-Al-Rashid commented 3 months ago

svg, attached app_icon

Jafar-Al-Rashid commented 3 months ago

webp version of this works but not svg

terrakok commented 3 months ago

Because Android doesn't support SVG resources. I will implement a special check during a build for that

okushnikov commented 1 month ago

Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.