realm-swift: Missing required modules: 'Realm.Private', 'Realm'

How frequently does the bug occur?

All the time

Description

Unable to use RealmSwift as a SPM dependency in a private ( local ) package. SetUp:

  1. Create a package (SPM) that contains 2 RealmObjects. This package has a dependency on RealmSwift.
  2. Add the local package as a dependency to a SampleApp (iOS application )
  3. Inside the SampleApp, for the main target, add the package framework as a linked dependency
  4. Inside the SampleApp, for the test target, don’t add any dependency .
  5. Add test on the test target, which will attempt to create the realm object from the local package
  6. Build the app / run . No problems found
  7. Attempt to build the test => “Missing required modules: ‘Realm.Private’, ‘Realm’”

Link to sample Project https://github.com/DanPavelNan/TestRealmWhitSPM

Stacktrace & log output

SwiftEmitModule normal arm64 Emitting\ module\ for\ NewReamTestTests (in target 'NewReamTestTests' from project 'NewReamTest')
    cd /Users/nanda1/ios/DanRepos/TestRealmWhitSPM/NewReamTest
    builtin-swiftTaskExecution -- /Users/nanda1/Downloads/Xcode14.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend -frontend -emit-module -experimental-skip-non-inlinable-function-bodies-without-types /Users/nanda1/ios/DanRepos/TestRealmWhitSPM/NewReamTest/NewReamTestTests/NewReamTestTests.swift -target arm64-apple-ios16.1-simulator -Xllvm -aarch64-use-tbi -enable-objc-interop -sdk /Users/nanda1/Downloads/Xcode14.1.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator16.1.sdk -I /Users/nanda1/Library/Developer/Xcode/DerivedData/NewReamTest-clynihkvwaxluhdndgunmpexywit/Build/Products/Debug-iphonesimulator -I /Users/nanda1/Downloads/Xcode14.1.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/lib -F /Users/nanda1/Library/Developer/Xcode/DerivedData/NewReamTest-clynihkvwaxluhdndgunmpexywit/Build/Products/Debug-iphonesimulator -F /Users/nanda1/Downloads/Xcode14.1.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Library/Frameworks -F /Users/nanda1/Downloads/Xcode14.1.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator16.1.sdk/Developer/Library/Frameworks -no-color-diagnostics -enable-testing -g -module-cache-path /Users/nanda1/Library/Developer/Xcode/DerivedData/ModuleCache.noindex -swift-version 5 -enforce-exclusivity\=checked -Onone -D DEBUG -serialize-debugging-options -serialize-debugging-options -enable-bare-slash-regex -empty-abi-descriptor -Xcc -working-directory -Xcc /Users/nanda1/ios/DanRepos/TestRealmWhitSPM/NewReamTest -resource-dir /Users/nanda1/Downloads/Xcode14.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift -enable-anonymous-context-mangled-names -Xcc -I/Users/nanda1/Library/Developer/Xcode/DerivedData/NewReamTest-clynihkvwaxluhdndgunmpexywit/Build/Intermediates.noindex/NewReamTest.build/Debug-iphonesimulator/NewReamTestTests.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/nanda1/Library/Developer/Xcode/DerivedData/NewReamTest-clynihkvwaxluhdndgunmpexywit/Build/Intermediates.noindex/NewReamTest.build/Debug-iphonesimulator/NewReamTestTests.build/NewReamTestTests-generated-files.hmap -Xcc -I/Users/nanda1/Library/Developer/Xcode/DerivedData/NewReamTest-clynihkvwaxluhdndgunmpexywit/Build/Intermediates.noindex/NewReamTest.build/Debug-iphonesimulator/NewReamTestTests.build/NewReamTestTests-own-target-headers.hmap -Xcc -I/Users/nanda1/Library/Developer/Xcode/DerivedData/NewReamTest-clynihkvwaxluhdndgunmpexywit/Build/Intermediates.noindex/NewReamTest.build/Debug-iphonesimulator/NewReamTestTests.build/NewReamTestTests-all-non-framework-target-headers.hmap -Xcc -ivfsoverlay -Xcc /Users/nanda1/Library/Developer/Xcode/DerivedData/NewReamTest-clynihkvwaxluhdndgunmpexywit/Build/Intermediates.noindex/NewReamTest.build/Debug-iphonesimulator/NewReamTestTests.build/all-product-headers.yaml -Xcc -iquote -Xcc /Users/nanda1/Library/Developer/Xcode/DerivedData/NewReamTest-clynihkvwaxluhdndgunmpexywit/Build/Intermediates.noindex/NewReamTest.build/Debug-iphonesimulator/NewReamTestTests.build/NewReamTestTests-project-headers.hmap -Xcc -I/Users/nanda1/Library/Developer/Xcode/DerivedData/NewReamTest-clynihkvwaxluhdndgunmpexywit/Build/Products/Debug-iphonesimulator/include -Xcc -I/Users/nanda1/Library/Developer/Xcode/DerivedData/NewReamTest-clynihkvwaxluhdndgunmpexywit/Build/Intermediates.noindex/NewReamTest.build/Debug-iphonesimulator/NewReamTestTests.build/DerivedSources-normal/arm64 -Xcc -I/Users/nanda1/Library/Developer/Xcode/DerivedData/NewReamTest-clynihkvwaxluhdndgunmpexywit/Build/Intermediates.noindex/NewReamTest.build/Debug-iphonesimulator/NewReamTestTests.build/DerivedSources/arm64 -Xcc -I/Users/nanda1/Library/Developer/Xcode/DerivedData/NewReamTest-clynihkvwaxluhdndgunmpexywit/Build/Intermediates.noindex/NewReamTest.build/Debug-iphonesimulator/NewReamTestTests.build/DerivedSources -Xcc -DDEBUG\=1 -module-name NewReamTestTests -disable-clang-spi -target-sdk-version 16.1 -emit-module-doc-path /Users/nanda1/Library/Developer/Xcode/DerivedData/NewReamTest-clynihkvwaxluhdndgunmpexywit/Build/Intermediates.noindex/NewReamTest.build/Debug-iphonesimulator/NewReamTestTests.build/Objects-normal/arm64/NewReamTestTests.swiftdoc -emit-module-source-info-path /Users/nanda1/Library/Developer/Xcode/DerivedData/NewReamTest-clynihkvwaxluhdndgunmpexywit/Build/Intermediates.noindex/NewReamTest.build/Debug-iphonesimulator/NewReamTestTests.build/Objects-normal/arm64/NewReamTestTests.swiftsourceinfo -emit-objc-header-path /Users/nanda1/Library/Developer/Xcode/DerivedData/NewReamTest-clynihkvwaxluhdndgunmpexywit/Build/Intermediates.noindex/NewReamTest.build/Debug-iphonesimulator/NewReamTestTests.build/Objects-normal/arm64/NewReamTestTests-Swift.h -serialize-diagnostics-path /Users/nanda1/Library/Developer/Xcode/DerivedData/NewReamTest-clynihkvwaxluhdndgunmpexywit/Build/Intermediates.noindex/NewReamTest.build/Debug-iphonesimulator/NewReamTestTests.build/Objects-normal/arm64/NewReamTestTests-master-emit-module.dia -emit-dependencies-path /Users/nanda1/Library/Developer/Xcode/DerivedData/NewReamTest-clynihkvwaxluhdndgunmpexywit/Build/Intermediates.noindex/NewReamTest.build/Debug-iphonesimulator/NewReamTestTests.build/Objects-normal/arm64/NewReamTestTests-master-emit-module.d -parse-as-library -o /Users/nanda1/Library/Developer/Xcode/DerivedData/NewReamTest-clynihkvwaxluhdndgunmpexywit/Build/Intermediates.noindex/NewReamTest.build/Debug-iphonesimulator/NewReamTestTests.build/Objects-normal/arm64/NewReamTestTests.swiftmodule -emit-abi-descriptor-path /Users/nanda1/Library/Developer/Xcode/DerivedData/NewReamTest-clynihkvwaxluhdndgunmpexywit/Build/Intermediates.noindex/NewReamTest.build/Debug-iphonesimulator/NewReamTestTests.build/Objects-normal/arm64/NewReamTestTests.abi.json

<unknown>:0: error: missing required modules: 'Realm.Private', 'Realm'

Can you reproduce the bug?

Yes, always

Reproduction Steps

Link to sample Project https://github.com/DanPavelNan/TestRealmWhitSPM

or zip TestRealmWhitSPM.zip

Version

10.32.3

What SDK flavour are you using?

Local Database only

Are you using encryption?

No, not using encryption

Platform OS and version(s)

iOS 16.1

Build environment

Xcode version: 14.1 Dependency manager and version: SPM

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 3
  • Comments: 17 (3 by maintainers)

Most upvoted comments

@Jaafar92 , I was struggling with the same issue. I solved the issue with making a wrapper on top of RealmSwift and used realm through it. Check the Swift Package in the following link: PersistentDataCore

@DanPavelNan I discussed this with the team, the approach I mentioned earlier was incorrect. What needs to be done is the library needs to be linked in a way that Xcode sees it as a dynamic library. the above approach links it as a static library and that is why you are seeing warnings like duplicate implementation of classes. I’ll try find some time to dig into finding the correct approach.

@DanPavelNan the solution is to add your custom package to the ‘Link Binary with Libraries’ section under your test target:

Screenshot 2022-11-30 at 13 41 05

I deleted derived data, re-added all my Swift Packages, and now I can get my app to build for iOS. But it still fails on my macOS app. Maybe I just need to add Realm with Carthage.

Same here. Haven’t been able to use SPM either with Realm ever because of issues like this one.