Hey folks, I'm having trouble loading a font in my...
# multiplatform
r
Hey folks, I'm having trouble loading a font in my android non-cmp module, I've declared the fonts in my compose multiplatform module like this:
Copy code
@Composable
fun Inter() = FontFamily(
    Font(Res.font.inter_regular, FontWeight.Normal),
    Font(Res.font.inter_medium, FontWeight.Medium),
    Font(Res.font.inter_semibold, FontWeight.SemiBold),
    Font(Res.font.inter_bold, FontWeight.Bold)
)
Then in my non-cmp module I use it like:
Copy code
Text(
    "Test",
    fontFamily = Inter()
)
But it crashes with this error:
Copy code
java.lang.IllegalStateException: Could not load font
   at androidx.compose.ui.text.font.TypefaceRequestCache.runCached(FontFamilyResolver.kt:207)
   at androidx.compose.ui.text.font.FontFamilyResolverImpl.resolve(FontFamilyResolver.kt:92)
   at androidx.compose.ui.text.font.FontFamilyResolverImpl.resolve-DPcqOEQ(FontFamilyResolver.kt:79)
...
Any ideas on how to fix this or properly access the fonts?
j
Do you want to only use it for a single text field?
r
No, in my actual case, there are many Text's
j
Copy code
@Composable
fun TitilliumTypography(): Typography {
    val titilliumFont = Font(Res.font.titilliumweb)
    val fontFamily = remember { FontFamily(titilliumFont) }

    return Typography(
        displayLarge = TextStyle(fontFamily = fontFamily),
        displayMedium = TextStyle(fontFamily = fontFamily),
        displaySmall = TextStyle(fontFamily = fontFamily),
        headlineLarge = TextStyle(fontFamily = fontFamily),
        headlineMedium = TextStyle(fontFamily = fontFamily),
        headlineSmall = TextStyle(fontFamily = fontFamily),
        titleLarge = TextStyle(fontFamily = fontFamily),
        titleMedium = TextStyle(fontFamily = fontFamily),
        titleSmall = TextStyle(fontFamily = fontFamily),
        bodyLarge = TextStyle(fontFamily = fontFamily),
        bodyMedium = TextStyle(fontFamily = fontFamily),
        bodySmall = TextStyle(fontFamily = fontFamily),
        labelLarge = TextStyle(fontFamily = fontFamily),
        labelMedium = TextStyle(fontFamily = fontFamily),
        labelSmall = TextStyle(fontFamily = fontFamily)
    )
}

MaterialTheme(typography = TitilliumTypography()) {
    KoinContext {
    }
}
I did it like this. This will be applied across the app
r
I tried this but its not working in non-cmp modules