Hello, does anyone know why I get this error when ...
# compose-desktop
d
Hello, does anyone know why I get this error when I try building my project? The imports work in the editor and I can run the code when using compose for desktop, but android fails to build:
I was using
1.2.0-alpha01-dev683
, I'll try updating to
686
right now
Same errors, here's my versions file:
Copy code
object Versions {
    //not used yet
//    const val serialization = "1.3.3"

    const val coroutines = "1.6.2"
    const val ktor = "2.0.2"
    const val okio = "3.1.0"

    const val kotlin = "1.6.21"
    const val compose = "1.2.0-alpha01-dev683"

    const val app = "0.0.1"
}
i
org.jetbrains.skia
package is available only in
desktopMain
sourceSet
d
Hmm, how should I convert an image from `ByteArray`(coming from a png like for example) to an
ImageBitmap
?
I'm trying to create a multiplatform image loading library and I don't know how to support all platforms and cache the images
i
Hmm, how should I convert an image from `ByteArray`(coming from a png like for example) to an
ImageBitmap
?
Create an expect/actual function. BitmapDecoder.kt in commonMain:
Copy code
expect fun ImageBitmap(bytes: ByteArray): ImageBitmap
BitmapDecoderDesktop.kt in desktopMain:
Copy code
actual fun ImageBitmap(bytes: ByteArray): ImageBitmap {
    // your code from the screenshot
}
BitmapDecoderAndroid.kt in androidMain:
Copy code
actual fun ImageBitmap(bytes: ByteArray): ImageBitmap {
    return BitmapFactory.decodeByteArray(bytes, 0, bytes.length).asImageBitmap()
}
🙏 1
d
Is there something similar available for `ios`/`js`?
i
The code for them should be the same as for desktop. They are built from the same sourceSet, which depends on Skiko library (Kotlin Skia bindings). Android depends on the native Android API, so the difference. In the future we can probably publish skikoMain sourceSet, so it is only needed to define your function twice, not 4 times.
👍🏻 1
d
Cool, I'll try that, thank you!
l
Funilly enough, i was also starting a lib for that just now. There is already https://github.com/alialbaali/Kamel but it doesnt seem to be mantained anymore and doesnt support JS
By the way @Igor Demin, the IDE thinks
org.jetbrains.skia
is available on the common source set, and lets you use it. But as @Dragos Rachieru mentioned, it only compiles for desktop.
👍🏻 1
d
@Lucas I was using that and it was no longer maintained, if you want to check my library out, it already works and has a sample for usage
l
Nice! I think that link is private tho, i cant access it
d
oh sorry, let me change it
done, should work now
l
It works! Very nice, gonna try it
d
It's still
wip
tho, it supports only
Url
for now
💯 1