`import org.jetbrains.compose.resources.resource` ...
# multiplatform
s
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
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
I have used for reading .html file
using readResourceBytes needs to test if this works
import org.jetbrains.compose.resources.readResourceBytes
j
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
Has anyone here used strings??? i am unable to use string resources
j
Yes I am using strings, whats the issue? Also would create separate post for that πŸ™‚
s
Res.readBytes not found on JB compose
j
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
which version of compose you get this? Res
We are in between some issue while generating iOS build so used RC version,
j
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
yes Jetbrains compose I mean
j
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
@Joel Denke How to create strings.xml and where to create???? if in composeResource->values then how to create there????
j
@SanjayKarki Please check demo app and their README in jetbrains repo πŸ™‚
s
s
@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
@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
@Suresh Maidaragi Oh right, yeah forgot ask about that, nice finding that! πŸ™‚
❀️ 1
169 Views