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

Suresh Maidaragi

02/29/2024, 8:21 AM
import org.jetbrains.compose.resources.resource
not found on latest version of Jetbrains Multiplatform Compose
v1.6.0-rc01
is this removed? what is the alternative if so?
j

Joel Denke

02/29/2024, 9:32 AM
What do you use the resource for in this case? Is it an image, font or something else?
if image is like painterResource(Res.drawable.image), for font is font(Res.font.myfont) I think. If other file type not supported by these, then you can do like Res.readBytes(Res.file.something) I think. I personally created my own Resource handler, to deal with video files as of example, where readBytes not sufficent for me. I hope Jetbrains will expose some kind of PlatformUri from their Resource class. Under the hood they using like:
Copy code
org.jetbrains.compose.resources.ResourceItem(setOf(), "values/strings.xml")
However do NOT use this, not recommended.
👍 1
s

Suresh Maidaragi

02/29/2024, 9:59 AM
I have used for reading .html file
using readResourceBytes needs to test if this works
import org.jetbrains.compose.resources.readResourceBytes
j

Joel Denke

02/29/2024, 10:01 AM
Its Res.readBytes I think and not readResourceBytes 🙂 Also recommend using 1.6.0 stable and not rc01. Its same API but some bug fixes for resources in that 😜
s

SanjayKarki

02/29/2024, 10:01 AM
Has anyone here used strings??? i am unable to use string resources
j

Joel Denke

02/29/2024, 10:02 AM
Yes I am using strings, whats the issue? Also would create separate post for that 🙂
s

Suresh Maidaragi

02/29/2024, 10:05 AM
Res.readBytes not found on JB compose
j

Joel Denke

02/29/2024, 10:06 AM
Then need to rebuild I think to get generated Res class in your module using compose resources 🙂
Should be there.
Should have something like this generated code in your module:
Copy code
@ExperimentalResourceApi
internal object Res {
  /**
   * Reads the content of the resource file at the specified path and returns it as a byte array.
   *
   * Example: `val bytes = Res.readBytes("files/key.bin")`
   *
   * @param path The path of the file to read in the compose resource's directory.
   * @return The content of the file as a byte array.
   */
  public suspend fun readBytes(path: String): ByteArray = readResourceBytes(path)

  public object drawable

  public object string

  public object font
}
But sure can probably use readResourceBytes directly if you prefer 🙂
s

Suresh Maidaragi

02/29/2024, 10:15 AM
which version of compose you get this? Res
We are in between some issue while generating iOS build so used RC version,
j

Joel Denke

02/29/2024, 10:20 AM
I use CMP 1.6.0, but got Res from 1.6.0-rc01 🙂
But youre not mean regular androidx compose, you mean jetbrains compose right?
💯 1
s

Suresh Maidaragi

02/29/2024, 10:22 AM
yes Jetbrains compose I mean
j

Joel Denke

02/29/2024, 10:29 AM
No they havent removed Res
However they changes how to get like Res.strings.myString, where need to import myString directly and not go through Res 🙂
But for root level of Res, readBytes still exists.
💯 1
If it doesnt get generated for you, something wrong in your setup most probably.
Or some other error propagates in something else interup the compile before Res get generated.
Also correcting myself its like this:
Copy code
public suspend fun readBytes(path: String): ByteArray = readResourceBytes(path)
Where not Res to send into readBytes, its the old way had in
resource("relativePath")
. Like
Res.readBytes("files/myfile.html")
s

SanjayKarki

02/29/2024, 10:41 AM
@Joel Denke How to create strings.xml and where to create???? if in composeResource->values then how to create there????
j

Joel Denke

02/29/2024, 10:45 AM
@SanjayKarki Please check demo app and their README in jetbrains repo 🙂
s

Suresh Maidaragi

02/29/2024, 10:55 AM
s

SanjayKarki

02/29/2024, 10:58 AM
@Joel Denke and @Suresh Maidaragi Thanks, managed to solve just by creating a normal file with .xml at the end and restarting the IDE, without restarting i was getting Res error
👍 2
s

Suresh Maidaragi

02/29/2024, 11:12 AM
@Joel Denke got the issue, I was using moko resources, along with Jetbrains compose 1.6.0-rc01 as just plugin & not added dependencies as shown here
implementation(compose.components.resources)
Due to which Res is not generated...
j

Joel Denke

02/29/2024, 1:10 PM
@Suresh Maidaragi Oh right, yeah forgot ask about that, nice finding that! 🙂
❤️ 1
38 Views