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.72k stars 1.14k forks source link

useResource and loadImageBitmap not Multiplatform: not defined for Android target #1456

Open sonique6784 opened 2 years ago

sonique6784 commented 2 years ago

I'm not able to use useResource and loadImageBitmap when targeting Android. I do use these functions on Desktop (Mac), and it works well.

val bitmap = useResource(fileName) { loadImageBitmap(it) }

I believe it is because useResource doesn't exists in the Android API, instead we have painterResource, fontResource...

https://developer.android.com/reference/kotlin/androidx/compose/ui/res/package-summary

# build.gradle config common module

 val commonMain by getting {
            dependencies {
                api(composemm.runtime)
                api(composemm.foundation)
                api(composemm.material)
                api(composemm.ui). // org.jetbrains.compose.ui:ui
                api(composemm.desktop.currentOs)
                implementation("org.openrndr:openrndr-math:0.3.47")
            }
        }
        val commonTest by getting {
            dependencies {
                implementation(kotlin("test"))
            }
        }
        val androidMain by getting {
            dependencies {
                api("androidx.appcompat:appcompat:1.4.0")
                api("androidx.core:core-ktx:1.6.0")
                api(ComposeAndroid.ui) // androidx.compose.ui:ui:1.0.0
                api(ComposeAndroid.runtime)
                api(ComposeAndroid.material)
                api(ComposeAndroid.ui)

            }
        }
Andrew0000 commented 10 months ago

My thoughts on Roman's answer here: While we are waiting K2, why not to warn users of the useResource function that it works only on desktop? Like it's done with expect/actual if you forget to implement all actuals.

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.