How do I get binary data embedded at compile time ...
# multiplatform
c
How do I get binary data embedded at compile time with multiplatform? I'm trying to use moko-resources with not so much success and I also hoped there was a KMP builtin. I have a file like 'data.txt' inside the commonMain and iosMain/resources/ directory
j
I'm assuming you mean resources specifically in iOS Kotlin/Native targets. Resource embedding works for JVM targets and somewhat works for Android as well. I shared a workaround for configuring embedding resources in Kotlin/Native targets here.
c
Hi Jeff, I did come across 2 of your useful posts about this. In my case I'm not sure how useful they were as we are developing an SDK that I believe doesn't have a bundle ID that I can hardcode properly into the source. Basically I have a source file like Loader.ios.kt which amongst other things needs to load a string at compile-time with binary data. I was not able to get your solution to work in this case. I managed to get moko-resources partially working. At least the IDE now autocompletes the resource. My issue earlier was that I had the file one-level higher located at iosMain/resources/MR/data.txt rather than iosMain/resources/MR/files/data.txt
j
Ok. This might be helpful context for what the bundle identifier should be for your KMP shared library.
c
Yes, I saw that post and tried that but I'm not entirely sure if that fits for us. At least the bundle IDs when I printed all of them seemed very off. I'll revisit that tomorrow to see if I missed something.
I did get some good direction from your posts though, so thank you anyway!
👍🏼 1
I've moved everything into our Swift package so avoided the whole problem now.
👍 1