1

Full reproducible example here

I'm working on a Jetpack Compose Multiplatform project. In my module ui-system, I have a drawable located at:

ui-system/src/commonMain/composeResources/drawable/compose-multiplatform.xml

When I try to run this code on Android using:

@Composable
fun Test() {
    Image(painter = painterResource(Res.drawable.compose_multiplatform), contentDescription = null)
}

I get the following error at runtime:

  Caused by: org.jetbrains.compose.resources.MissingResourceException: Missing resource with path: composeResources/reproduce.ui_system.generated.resources/drawable/compose-multiplatform.xml
                                                                                                        at org.jetbrains.compose.resources.ResourceReader_androidKt$getPlatformResourceReader$1.getResourceAsStream(ResourceReader.android.kt:82)
                                                                                                        at org.jetbrains.compose.resources.ResourceReader_androidKt$getPlatformResourceReader$1.read(ResourceReader.android.kt:29)
    ...

The file exists, the path seems correct, the reference is generated correctly as well and the module uses org.jetbrains.compose.resources. I have tried:

  • Clean and Rebuild
  • Check if resources are actually present

Still, the resource isn't found when running on Android (I only tested Android so far).

Has anyone encountered this issue with resources in a secondary module in Compose Multiplatform? Am I missing something?

1 Answer 1

6

The issue can be resolved by adding the following to the module's build.gradle.kts

kotlin {
  androidLibrary {
    experimentalProperties["android.experimental.kmp.enableAndroidResources"] = true
  }
}
Sign up to request clarification or add additional context in comments.

3 Comments

How will it work on iOS?
From what I've got it will work out of the box on iOS. But I didn't test it. youtrack.jetbrains.com/issue/CMP-7751/…
I also had this problem and fixed it by adding experimentalProperties['android.experimental.kmp.enableAndroidResources'] = true. Thanks for this solution.

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.