Home > database >  Kotlin Multiplatform ~ Add images on Android and Desktop
Kotlin Multiplatform ~ Add images on Android and Desktop

Time:12-27

I have a problem that I thought would be very simple, but somehow I managed to spend all day searching for a solution and am none the wiser.

Basically, I have a Kotlin Multiplatform app using Compose, which is supposed to work for both Android and Desktop, and so far it does. However, now I want to add a simple title image, and I haven't been able to figure out how to do that.

What I want is to have one image file somewhere - anywhere - in my project structure and have that file be used for both Android and Desktop. Furthermore, I want the image to be loaded in the common UI module, which I think is one of the things that makes this complicated.

As far as I can tell, in Compose, the general way to add an image is like this:

    val image: Painter = painterResource(id = R.drawable.composelogo)
    Image(painter = image,contentDescription = "")

The problem here is that the R seems to be specific to the Android module, while I want to load the image in the common-ui module. For reference, here's my rough project structure:

           
  • Related