getting this issue on latest dev release, any one ...
# compose-ios
k
getting this issue on latest dev release, any one else facing this https://github.com/JetBrains/compose-multiplatform/issues/4120
i
сс @Konstantin Tskhovrebov
✔️ 1
k
Resources like drawables, strings and fonts should be used by generated accessors. Not by path. Your code uses internal API. I will hide it the future releases, I guess
to read a resource by path as bytearray there is a special folder:
composeResources/files
and function Res.readResource("path")
k
@Konstantin Tskhovrebov thanks for replying, i am using this as i have a multi module project and the resources are in shared module. The generated Res is available only in shared not in rest of the modules, how can i make this work?
k
1. the resources lib doesn't support multimodule projects yet 2. in the future resources will be isolated by modules. so, to have access to some module's resources, module has to provide own api for that. like "readMyResourceA()"
k
So i cant use the hack anymore
k
yes.
😞 1
you should't use the hack because a relative path to resources will be changed any time
and you don't have compile time checks to know about it
k
I agree, but a question here since all the resources are in shared module which is the only module ios knows about and android works fine. Why is that only ios can’t retrieve these resources?
k
android resources works fine in multimodule projects because of the JVM 🙂 because for an android app there are aar archives for each gradle module. and resources are inside. but for the native world there is no the same thing
k
makes sense thanks @Konstantin Tskhovrebov
m
I think for know you can abstract it. You can have an interface for loading resources available for all modules:
Copy code
interface Resource {
    suspend fun loadRes(path: String): ByteArray
}
And it can be implemented in the shared module with all the resources, it can receive an Enum instead of String also
Copy code
class ResourceImpl: Resource {
    override suspend fun loadRes(res: Res): ByteArray = when(res) {
        Res.Close -> ...
}
}
And then provide this interface from shared module to the rest of the app with DI or CompositionLocals
k
thanks @mohamed rejeb thats what i am doing now with composition locals,
m
Cool, is it working fine?
k
i am currently working on, will update in half an hour. fingers crossed
m
Nice, I hope we will be able to use resources across different modules soon, it's really important.
k
working on that
kodee happy 4
k
@Konstantin Tskhovrebov is there a way i can change package name of generated Res?
k
Configure module group
k
can you give an example?
@mohamed rejeb this didnt work on ios, i ended up using another hack, i excluded resources dependency and added 1.4,3 compose dependency in common main. Now android can use resources using the new method and ios can use the old path method. Its not the right thing to do but it works.
j
Copy code
in the future resources will be isolated by modules. so, to have access to some module's resources, module has to provide own api for that. like "readMyResourceA()"
Does this mean if I have lets say a core module shared module and other feature modules depending on, I cant access it? In similar way that android has transitiveR8Class, isnt it possible to share Res class across all Gradle modules somehow, where all modules inject their resources into a global Res class?