I’m working on a multi-module Compose Multiplatform (CMP) project and created a new CMP library module using libs.plugins.multiplatform.library.
However, when I added font resources and tried to use them, I encountered this error at runtime:
java.lang.IllegalStateException: Could not load font
Caused by: java.lang.IllegalStateException: Unable to load font
What I Tried and Expected Results
- I checked if the font files were correctly added to the
resourcesfolder. ✅ - I confirmed that my
build.gradle.ktswere correctly set up. ✅
Expected Behavior: Fonts should load properly without any runtime exceptions.
Actual Behavior: The app crashes due to IllegalStateException.
Solution That Worked for Me
The issue was resolved by removing libs.plugins.multiplatform.library and using libs.plugins.android.library instead.
Fixed Module-Level build.gradle.kts
plugins {
alias(libs.plugins.compose)
alias(libs.plugins.multiplatform)
alias(libs.plugins.compose.compiler)
alias(libs.plugins.android.library) // ✅ Fix: Use android.library instead
}
Fixed Project-Level build.gradle.kts
plugins {
alias(libs.plugins.multiplatform) apply false
alias(libs.plugins.multiplatform.library) apply false
alias(libs.plugins.compose.compiler) apply false
alias(libs.plugins.compose) apply false
alias(libs.plugins.android.application) apply false
alias(libs.plugins.android.library) apply false // ✅ Added
}
Version Catalog libs.versions.toml
[plugins]
android-library = { id = "com.android.library", version.ref = "agp" } # ✅ Added
commonMainyou should put your fonts insidecomposeResources