MissingResourceException in iOS app with Kotlin Multiplatform library

58 Views Asked by At

I created a Kotlin Multiplatform module (as library) in my existing Android project. The goal is to build stuff once in that shared library and reuse it on iOS. I managed to build one first Composable that is provided in an XCFramework to the pre-existing iOS project via assembleXCFramework gradle task. So far so good...

Then I added a drawable to commonMain that is being used in the Composable view. Followed all the steps in guides and docs, which means I added a "composeResources" directory to "commonMain" and put my vector XML file in a "drawable" folder. Also added sourceSets["main"].resources.srcDirs("src/commonMain/composeResources") to the android section my Gradle file. With that I was able to successfully use the drawable in my Composable and it runs fine in Android.

The issue that I am facing right now is that I can't figure out how to provide resources like the drawable via an XCFramework to the iOS project. Because when running the iOS app now I am running into this exception

Uncaught Kotlin exception: org.jetbrains.compose.resources.MissingResourceException: Missing resource with path: drawable/ic_my_health.xml

which tells my the file is not available when running in iOS. I also couldn't find it being bundled into the XCFramework.

How can I bundle resources into an XCFramework? Are there better alternatives to using an XCFramework in this case? I would not like to use Cocoapods, because all my iOS project's dependencies are handled via Swift Package Manager.

I looked into moko-resources (https://github.com/icerockdev/moko-resources), but it seems it is only made to handle resource usage in an Multiplatform app, but not in a library.

Same question on YouTrack: https://youtrack.jetbrains.com/issue/KT-66790/MissingResourceException-in-iOS-app-with-Multiplatform-library

0

There are 0 best solutions below