https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
y

ynsok

02/18/2022, 11:50 AM
Hi 😄 Is there a possibility for keeping resources(strings, dimens, colors) in the common module and then used in shared Compose compositions that are kept in commonMain?
m

Michael Paus

02/18/2022, 12:56 PM
y

ynsok

02/21/2022, 2:28 PM
Moko resource is platform dependent
m

Michael Paus

02/21/2022, 2:38 PM
It seems you are right, despite the fact that it is labeled as “Multiplatform”. Only the API seems to be multi-platform but not the underlying mechanism. So you can’t share the actual resources in some common fashion. Please correct me if I am wrong. What are the relevant platforms for you then? In my case (only Android and Desktop) I just use the good old Java way of storing and retrieving resources. That still works on Android too although it is not very common.
y

ynsok

02/21/2022, 2:45 PM
I’m also writing application on Android and Desktop. Do you have any samples or resources on how can I achieve the same approach?
m

Michael Paus

02/21/2022, 3:00 PM
I just created a folder “resources” under “commonMain” and put all common resources in there. I also have “resources” folders under “desktopMain” and “androidMain” for platform specific resources like, e.g., “META-INF/services/some service declaration”. You can then access these via the usual Java mechanisms, e.g.:
Copy code
SomeClass::class.java.getResource(resourceName)
Note! This works only as long as you restrict yourself to the Java world!