1

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.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
1
  • Is it possible to share the folder structure of your project? if your module has a commonMain you should put your fonts inside composeResources Commented Mar 21 at 10:45

1 Answer 1

1

If we kept resources under separate module & tried to access from different module, above runtime error we are getting; this is because main module can't actually able to access the resources from other modules.

I was also facing the same issue in compose version 1.7.3. It is fixed in 1.8.0-rc1

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.