'Can't use a font in Kotlin Multiplatform
Pretty simple; just created a Compose Multiplatform project from the wizard.
Went ahead and created the Theme; but I wanted to use the same font so I put poppins.ttf inside commonMain/resources/font/.
Then I declared the following in commonMain module:
expect val projectFontFamily: FontFamily
On the commonDesktop module I used:
actual val projectFontFamily: FontFamily = FontFamily(
Font("font/poppins.ttf")
)
Great, that worked. Now on commonAndroid:
actual val projectFontFamily: FontFamily = FontFamily(
Font(R.font.poppins)
)
For some reason the R class is not properly being generated and I cannot use R.font.poppins.
If I rename "resources" to "res" and shove the font into res/font/ then it works. (But I just duplicated the font file).
How do I get around doing this?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
