Hi guys, how do I get Android resource ID from KMP resources? Tried several approaches and it just doesn't find my resource
p
Phuc
11/21/2024, 9:43 AM
What did you do @buszi0809?
Phuc
11/21/2024, 9:45 AM
Did you try to Rebuild/Make Module?
b
buszi0809
11/21/2024, 9:47 AM
tried using
Res.readBytes
and then decode those bytes into anything Android related (Bitmap, VectorDrawable etc.) and it doesn't work
tried using the method to find identifier and it also doesn't find it
I try to post a Notification on the Android side, and I need to pass either Android resource ID or some wrapped bitmap, and I just can't find a way to access the multiplatform resource in "Android way"
buszi0809
11/21/2024, 9:49 AM
also tried
Res.getUri
and then decode it somehow into a Bitmap, but it just seems to not be compatible with Android drawables
✅ 1
buszi0809
11/21/2024, 9:54 AM
the resource itself seem to be present, because
Res.readBytes
actually returns some bytes, but I can't find a way to make it work with Android-specific stuff
buszi0809
11/21/2024, 10:43 AM
now I've found out those resources are kept in assets, so I tried to do something like this:
Copy code
val parser = assets.openXmlResourceParser(
"assets/composeResources/*app name*.composeapp.generated.resources/drawable/compose-multiplatform.xml"
)
val drawable = VectorDrawableCompat.createFromXml(resources, parser)
val bitmap = drawable.toBitmap()
val icon = IconCompat.createWithBitmap(bitmap)
but I'm getting
java.io.FileNotFoundException: Corrupt XML binary file