androidandroid-jetpack-composekotlin-multiplatformcompose-multiplatform

Compose Multiplatform Project (Android Target): Resources not working in module


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:

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?


Solution

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

    kotlin {
      androidLibrary {
        experimentalProperties["android.experimental.kmp.enableAndroidResources"] = true
      }
    }