I am trying to create an android font from a CMP p...
# multiplatform
d
I am trying to create an android font from a CMP path uri.
Res.getUri
does not say that the file doesn't exist, but
file.exists()
prints false.
Copy code
val file = File(Res.getUri("font/RobotoFlex-Variable.ttf"))

    println(file.exists())
    return FontFamily(
        Font(
            File(Res.getUri("font/RobotoFlex-Variable.ttf")),
            variationSettings = FontVariation.Settings(
                FontVariation.width(width),
                FontVariation.weight(weight)
            )
        )
    )
The file prints this path:
file:/android_asset/composeResources/esmvertretungsplan.composeapp.generated.resources/font/RobotoFlex-Variable.ttf
From my further reading, I understand that I cannot create a
File
object from a file that is an app resource and not on the actual system. What are my options then?
a
If you're trying to use the font just do Res.font.your-font. Make sure its under the compose resources , under the font folder. It might not show the import, but just run your project and it might fail then the option to import will show when you check
d
I needed to do that in androidMain so compose resources didn't work. I don't know why I didn't think about it earlier but what I just eneded up doing is copying the font to android resources and accessing it through R.
👍 1