1

I need to integrating unit test for my app with Realm Swift. But it always report issue even import RealmSwift has been added:

Missing required modules: 'Realm.Private', 'Realm'

Then I tried to add Realm & realmSwift in "Build Phase/Link Binary With Libraries", but it crashes directly with error report:

Class _TtGC10RealmSwift4ListC3AMA14ROOperatorItem_ is implemented in both ?? (0x7fdf040223b8) and ?? (0x7fdf040c8468). One of the two will be used. Which one is undefined.

Finally I found the solution on its official website https://www.mongodb.com/docs/realm/sdk/swift/test-and-debug/

enter image description here

But I'm using SPM to manage packages, not the local embed Realm & RealmSwift frameworks, in such a way, what's the parent path to RealmSwift.framework?

You can download a simple sample project that reproduce the issue from OneDrive: RealmUnitTestError_GitHub

This is a similar question on stackoverflow, but all answers are not work now:

"Missing required module 'XYZ'" on Unit Tests when using Swift Package Manager

And some discussions on Github:

https://github.com/apple/swift-nio/issues/1128#issuecomment-527566361

Thank you very much in advance!

stephen
  • 519
  • 6
  • 22
  • It doesn't sound like Realm was added to the project using the normal process as outlined here [Add Realm Using SPM](https://www.mongodb.com/docs/realm/sdk/swift/install/#installation). Was it? – Jay Feb 27 '23 at 23:07
  • Realm was added using normal process with SPM, and everything works fine. The issue happened just for Test Target. If I “import RealmSwift” directly, off course with “@testable” for main project, it reports missing error. If I add “Realm.framework & RealmSwift.framework” to Link Binary With Libraries that try to solve previous error, it crashes when click the test play button, seems with a repeat error. Mongodb documents to solve issues by adding Parent Path to Test Target “Framework Search Paths”, what I want to know is where is Parent Path? – stephen Feb 28 '23 at 00:02
  • @Jay I upload a project that reproduce the erros for Test Target: https://1drv.ms/u/s!Ank9gPMc1GKYk_UsRZgSq0Yd_ZHyQg?e=aOLcPZ – stephen Feb 28 '23 at 14:53
  • I downloaded built and ran the project. No errors were encountered and Hello, world! with a globe icon is displayed. What's the process for duplicating the issue? – Jay Feb 28 '23 at 21:11
  • @Jay The error is just encountered for Test Target, please try to run the unit test ‘testSumList’ in ‘RealmUnitTestErrorTests’ – stephen Feb 28 '23 at 22:29
  • Gotcha. Yeah, that duplicated. I actually created a totally Fresh project, added Realm through SPM and tried the code in your project and got the same results. That also lead to other issues along the way; [Missing Required Modules](https://github.com/realm/realm-swift/issues/8047) being one of them. One thing to note: Realm's List and Swifts List is a naming collision so whenever you reference a Realm List do so like this `RealmSwift.List`. Unrelated but can be problematic. – Jay Mar 01 '23 at 21:49
  • @Jay Yep! But even I prepend `RealmSwift` before `List` to distinguish `SwiftUI List`, it still crashed for duplicate error, and if we remove Realm frameworks from `Link Binary With Libraries` for Test Target, it will report Missing Required Modules. Hope Realm Team will solve this bug soon. Thanks very much for your help! – stephen Mar 02 '23 at 10:40
  • Can you please file a [github bug report](https://github.com/realm/realm-swift/issues)? Maybe we are overlooking something but it would be best to have more eyes on the issue. – Jay Mar 02 '23 at 18:11
  • Please check [GitHub Bug Report](https://github.com/realm/realm-swift/issues/8158) – stephen Mar 03 '23 at 13:40

3 Answers3

2

There appears to be a 'fix' for this so posting it as an answer for completeness.

The issue is a conflict and/or disconnect between the Realm Library and RealmSwift Library. The fix is to change the Linked Binaries in the Test targets

  1. On the main app target, leave the Realm and RealmSwift libraries in the Linked Binary With Library section enter image description here

  2. On the Test Target(s) remove the RealmSwift library from the Linked Binary With Library section and leave only the Realm library enter image description here

Jay
  • 34,438
  • 18
  • 52
  • 81
1

It works for me: select Build Phases - Link Binary With Libraries in xxxTest.xcodeproj file, and add RealmSwift library.

GaoXiang
  • 11
  • 1
-1

Try this: add /path/to/RealmSwift.framework/Frameworks to the “Framework Search Paths” section in Build Settings. In more details: Adding RealmSwift as a subproject: Missing required modules: 'Realm.Private', 'Realm'

General Grievance
  • 4,555
  • 31
  • 31
  • 45