Hi I am relatively new to compose multiplatform an...
# multiplatform
r
Hi I am relatively new to compose multiplatform and have a problem with dependencies: I added
compose-ui = { group = "androidx.compose.ui", name = "ui", version.ref = "compose" }
(compose version
1.6.2
as it is when generating a project on: https://kmp.jetbrains.com) I added the dependency under
commonMain.dependencies
as
implementation(libs.compose.ui)
. Whe I try to build the android app, I get the following errors:
Copy code
Unresolved reference: toComposeImageBitmap
Unresolved reference: toComposeImageBitmap
Unresolved reference: toComposeImageBitmap
Unresolved reference: drawImage
First error is on the import:
import androidx.compose.ui.graphics.toComposeImageBitmap
second and third are on usage. The drawImage error is on
Copy code
drawIntoCanvas {
    it.nativeCanvas.drawImage(Image.makeFromBitmap(bitmap), l.toFloat(), t.toFloat())
}
What am I doing wrong?
m
I can use androidx.compose.ui.graphics.toComposeImageBitmap without that import.
Not sure which one but these are my relevant imports that could contain it:
implementation(compose.runtime)
implementation(compose.material3)
implementation(compose.materialIconsExtended)
_@OptIn_(org.jetbrains.compose._ExperimentalComposeLibrary_::_class_)
implementation(compose.components.resources)
Ohh wait i think you cant use Skiko APIs in the common / Android part of your code
r
Ok, so I have to separate these into the platform code and use
toComposeImageBitmap
there?
m
Yes, but to avoid too much duplicated code i would do the image parsing natively and use this interface in common androidx.compose.ui.graphics.ImageBitmap
r
Ok, thanks, that worked 🙂 on android implementation I have
Copy code
actual fun Bitmap.toComposeImageBitmap(): ImageBitmap = this.toComposeImageBitmap()
and under desktop I have
Copy code
actual fun Bitmap.toComposeImageBitmap(): ImageBitmap = Image.makeFromBitmap(this).toComposeImageBitmap()
m
👍