5

Setup

iOS, xCode 13, Realm 10.20

MainProject integrates two swift packages using Swift Package Manager: LayerPersistence and LayerNetwork.

LayerPersistence packages has a dependency on

  • Realm

LayerNetwork packages has a dependency on

  • Alamofire

MainProject builds and runs without issues. Tests for MainProject do not build. Generates the following:

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

When I exclude LayerPersistence from the MainProject -> Tests run with no issues.

What I tried and it didn't work

I have tried to manually map the module with: -fmodule-map-file=.....some path to file.....Realm.modulemap but without success.

I have tried to include Realm manually in link binary with libraries of the test targets.

What works

Downgrading to Realm Version 5.5.2 in the LayerPersistence and manually linking Realm to all tests targets of the MainProject via

Build Phases -> Link Binary With Libraries

does the trick, but keeps me out of new Realm Versions.

Objective

To have the most recent version of Realm in the package integrated via SPM and still be able to run test in the MainProject


Note:

Tests in LayerPersistence and LayerNetwork run without issues.

There are some solutions in Internet but they do not resolve issues with the newer versions of Realm:

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

https://github.com/realm/realm-swift/issues/6301

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

Milos Dimic
  • 171
  • 1
  • 6
  • Did you try building a project from scratch with ONLY Realm? When you say *"two Swift packages, LayerPersistence and LayerNetwork"* what are those and why are you using them? Are you using Realm and AlamoFire? We need a bit more detail to understand what you're asking. – Jay Dec 18 '21 at 14:36
  • Hi @Jay. I have tried to build it only with Realm, no success. Two Swift packages are used to encapsulate the logic analog to their naming. They contain the boilerplate code related to their sphere. I am using Realm and Alamo as already described in the question. Concrete implementation of the imported swift packages is here really not important. Package can contain only IMPORT RealmSwift and it would prevent the tests from running in the MainProject. – Milos Dimic Dec 19 '21 at 06:00
  • Maybe I wasn't clear. Part of troubleshooting is eliminating variables, and you have a bunch. So, my question is; if you create a project from scratch, just a blank one, and then add Realm to the project using SPM does it compile and work? If not, you know the issue is with Realm or SPM. If it does work, you can eliminate those and do the same for AlamoFire.. SO is a terrible interactive debugger for installation type issues - it's really for coding specific issues so narrowing down the cause of the issue is best practice. – Jay Dec 19 '21 at 13:27
  • Please read the question again. It should be clear that there are almost no variables. MainProject imports LayerPersistence. LayerPersistence imports Realm. Tests in MainProject do not run when Realm version higher than 5.5.2 is used. – Milos Dimic Dec 24 '21 at 03:54
  • One more time.... You have several variables 1) Main Project 2) LayerPersistence 3) LayerNetwork 4) AlamoFire. Any one of those could be causing the issue. There are 4 possibilities and therefore 4 variables. That's too many. We need to reduce those. You can eliminate one of them by creating a brand new project from scratch and adding Realm to it. If it works, then you know Realm is NOT the cause. Then, create a new project and include AlamoFire. if that works, then you can eliminate that one. None of us knows what `LayerPersistence` is so it will be up to you to investigate that. – Jay Dec 24 '21 at 16:25

0 Answers0