Hi guys, how do I get Android resource ID from KMP...
# compose
b
Hi guys, how do I get Android resource ID from KMP resources? Tried several approaches and it just doesn't find my resource
p
What did you do @buszi0809?
Did you try to Rebuild/Make Module?
b
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
Copy code
resources.getIdentifier(
                        "compose_multiplatform",
                        "drawable",
                        packageName,
                    )
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"
also tried
Res.getUri
and then decode it somehow into a Bitmap, but it just seems to not be compatible with Android drawables
1
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
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
, so yeah, still no idea what to do sad panda
120 Views