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
resources
folder. ✅ - I confirmed that my
build.gradle.kts
were 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.pluginspose)
alias(libs.plugins.multiplatform)
alias(libs.pluginsposepiler)
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.pluginsposepiler) apply false
alias(libs.pluginspose) 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