CodexBloom - Programming Q&A Platform

how to to Use Custom Fonts in Jetpack Compose with Android 14: Font Not Found scenarios

👀 Views: 27 đŸ’Ŧ Answers: 1 📅 Created: 2025-06-07
jetpack-compose android-14 custom-fonts Kotlin

I'm testing a new approach and I'm building a feature where I'm working on a personal project and I've searched everywhere and can't find a clear answer... After trying multiple solutions online, I still can't figure this out. I'm trying to implement custom fonts in my Jetpack Compose app targeting Android 14, but I keep running into a 'Font not found' behavior at runtime. I've placed my font files in the `res/font` directory and referenced them correctly in my `Text` composables. Here's how I'm currently trying to set it up: ```kotlin val customFont = FontFamily(Font(R.font.my_custom_font)) Text( text = "Hello, World!", fontFamily = customFont, fontWeight = FontWeight.Bold, fontSize = 20.sp ) ``` However, when I run my app, I see the following behavior in the logcat: ``` java.lang.RuntimeException: Font not found: my_custom_font ``` I've double-checked that the font file name matches exactly what I'm referencing in the code, including the casing. I've also tried cleaning and rebuilding the project, but the scenario continues. Is there a specific way to include custom fonts in Compose that's different from traditional XML layouts? Any help would be greatly appreciated! Am I missing something obvious? I'm working on a service that needs to handle this. Thanks in advance! My team is using Kotlin for this application. I appreciate any insights! Am I approaching this the right way?