https://kotlinlang.org logo
Title
s

Shabinder Singh

02/09/2021, 7:01 PM
Hey All, I am sharing Compose code in Android And Desktop , only thing left is Drawables.. Any approach to use local resources in common code, As there is vectorXmlResource() method for desktop & painterResource()/vectorResource() for Android , But No method to use in Common/Shared Compose Code...
j

jim

02/09/2021, 7:05 PM
I think a shared resource system is going to need to be on our todo list, but it might not happen until after Jetpack Compose 1.0. In the mean time, you can define your own expect/actual that loads resources using whatever identifier you choose for common code, and loads it using platform-specific actuals.
s

Shabinder Singh

02/09/2021, 7:07 PM
Tried with no luck , Giving this Error
@jim for once app started like this but after building and rebuilding multiple times always above NoSuchMethod Error
Can u show how Actual/Expect you expect to be used for Res Loading?
j

jim

02/09/2021, 7:16 PM
There is an example in https://github.com/JetBrains/compose-jb/tree/master/examples/widgetsgallery where
imageResource
(defined in the various
Resources.kt
files) is an expect/actual resource loader for ImageBitmaps. The code you have looks approximately/decently correct, only thing I can think of is that maybe your modules / platform types aren't setup correctly. If you think it's setup correctly and is a bug in the Compose Compiler, please provide a minimal sample and we can investigate further.
👍 1
i

Igor Demin

02/09/2021, 9:57 PM
NoSuchMethodError
If I remember correctly, multiplatform plugin had the issue, when we create files with same names in androidMain/desktopMain. For example instead of Resources.kt in androidMain / desktopMain we should name files as AndroidResources.kt and DesktopResources.kt
😂
s

Shabinder Singh

02/10/2021, 4:51 AM
@Igor Demin Thankyou, Finally did work , I was Refactoring all code creating new project to verify crash and all that(Even thought about dropping Compose-Desktop until stable 1.0 comes)😶, you saved my lot of time & energy.
🎉 1