Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error loading RealmSwift dynamic framework in macOS app #8575

Closed
x-creates opened this issue May 4, 2024 · 13 comments
Closed

Error loading RealmSwift dynamic framework in macOS app #8575

x-creates opened this issue May 4, 2024 · 13 comments

Comments

@x-creates
Copy link

x-creates commented May 4, 2024

💡 UPDATE: 2024-06-10 Try the workaround provided by @zhanswift below #8575 (comment)

How frequently does the bug occur?

Always

Description

I'm encountering an issue loading the RealmSwift framework in my macOS app, and I'm hoping someone can provide some guidance.

I'm using Xcode 15.3 and have the RealmSwift 10.50.0 framework installed as a dependency in my project. The error suggests that the framework is not being correctly referenced or found during runtime. Build can be done successfully, though.

The error complains that the file '/Users//Library/Developer/Xcode/DerivedData/Foo-/Build/Products/Debug/RealmSwift.framework/Versions/A/RealmSwift' does not exist. It also states that the code signature for 'RealmSwift.framework/Versions/A/RealmSwift' (with the identifier <68E4E55B-1392-3E7B-B51C-B2FE88455CD8>) is not valid for use in the process, as the mapping process and the mapped file have different Team IDs.

I have ensured that I only included RealmSwift and made it an embedded and signed option.

Has anyone else encountered this issue before? If so, what steps did you take to resolve it? Any guidance would be greatly appreciated.

I have attached the sample project Foo.zip. You can download it from this link: [Foo.zip(https://github.com/realm/realm-swift/files/15208298/Foo.zip). I can confirm that downgrading the library to version 10.49.2 solved the issue.

Stacktrace & log output

dyld[11169]: Library not loaded: @rpath/RealmSwift.framework/Versions/A/RealmSwift
  Referenced from: <59A4BF84-B08D-338E-8F6D-83EDC110D43D> /Users/*/Library/Developer/Xcode/DerivedData/Foo-*/Build/Products/Debug/Foo
  Reason: 
    tried: '/Users/*/Library/Developer/Xcode/DerivedData/Foo-*/Build/Products/Debug/RealmSwift.framework/Versions/A/RealmSwift' (no such file),
    '/Users/*/Library/Developer/Xcode/DerivedData/Foo-*/Build/Products/Debug/PackageFrameworks/RealmSwift.framework/Versions/A/RealmSwift' (code signature in <68E4E55B-1392-3E7B-B51C-B2FE88455CD8> '/Users/*/Library/Developer/Xcode/DerivedData/Foo-*/Build/Products/Debug/PackageFrameworks/RealmSwift.framework/Versions/A/RealmSwift' not valid for use in process: mapping process and mapped file (non-platform) have different Team IDs),
    '/Users/*/Library/Developer/Xcode/DerivedData/Foo-*/Build/Products/Debug/PackageFrameworks/RealmSwift.framework/Versions/A/RealmSwift' (code signature in <68E4E55B-1392-3E7B-B51C-B2FE88455CD8> '/Users/*/Library/Developer/Xcode/DerivedData/Foo-*/Build/Products/Debug/PackageFrameworks/RealmSwift.framework/Versions/A/RealmSwift' not valid for use in process: mapping process and mapped file (non-platform) have different Team IDs),
    '/System/Volumes/Preboot/Cryptexes/OS/Users/*/Library/Developer/Xcode/DerivedData/Foo-*/Build/Products/Debug/PackageFrameworks/RealmSwift.framework/Versions/A/RealmSwift' (no such file),
    '/Users/*/Library/Developer/Xcode/DerivedData/Foo-*/Build/Products/Debug/PackageFrameworks/RealmSwift.framework/Versions/A/RealmSwift' (code signature in <68E4E55B-1392-3E7B-B51C-B2FE88455CD8> '/Users/*/Library/Developer/Xcode/DerivedData/Foo-*/Build/Products/Debug/PackageFrameworks/RealmSwift.framework/Versions/A/RealmSwift' not valid for use in process: mapping process and mapped file (non-platform) have different Team IDs),
    '/System/Volumes/Preboot/Cryptexes/OS/Users/*/Library/Developer/Xcode/DerivedData/Foo-*/Build/Products/Debug/PackageFrameworks/RealmSwift.framework/Versions/A/RealmSwift' (no such file)

Logging Error: 
  Failed to initialize logging system. Log messages may be missing. If this issue persists, try setting IDEPreferLogStreaming=YES in the active scheme actions environment variables.

The issue at #8571 appears to be a similar problem.

Can you reproduce the bug?

Always

Reproduction Steps

  1. Create a new macOS command-line project.
  2. Follow the instructions at https://www.mongodb.com/docs/atlas/device-sdks/sdk/swift/install/ to install Realm.
  3. Enable Realm as a dynamic framework, embed it, and sign it.
  4. Import RealmSwift in the main.swift file.
  5. Run the app.

Version

10.50.0

What Atlas Services are you using?

Local Database only

Are you using encryption?

No

Platform OS and version(s)

14.4

Build environment

Xcode version: 15.3
Dependency manager and version: ...

2024050407042Ibok6jk
202405040704xXdBXUt5

Copy link

sync-by-unito bot commented May 4, 2024

➤ PM Bot commented:

Jira ticket: RCOCOA-2350

@x-creates x-creates changed the title Error loading RealmSwift framework in macOS app Error loading RealmSwift dynamic framework in macOS app May 4, 2024
@anton-plebanovich
Copy link

I have the same issue. Though my dependency graph might be more complex the problem is the same. I also tried to use Archive but it did not help.

@anton-plebanovich
Copy link

This answer was helpful https://stackoverflow.com/a/73844861/4124265

I had to manually sign all frameworks in the PackageFrameworks directory to be able to run the executable successfully. This looks like an Xcode issue or I may be missing a proper build configuration to resign frameworks automatically. I faced the issue initially using None team and Sign to Run Locally option but even with other team and options it does not seem to work

@anton-plebanovich
Copy link

I had to add post-build action as a workaround fix with this script:

# Resigning as a workaround for https://github.com/realm/realm-swift/issues/8575

# Framework resign
for framework_path in "${BUILT_PRODUCTS_DIR}/PackageFrameworks/"*/; do
  framework_dir=$(basename "${framework_path}")
  framework_name="${framework_dir%.*}"
  framework_binary_path=`find "${framework_path}" -type f -name "${framework_name}"`
  echo "Fixing code sign issue for '${framework_name}' framework: ${framework_binary_path}"
  codesign -f -s - "${framework_binary_path}"
done

# Executable resign
codesign -f -s - "${CODESIGNING_FOLDER_PATH}"

@ukushu
Copy link

ukushu commented May 21, 2024

Downgrade to 10.49.0 resolved issue.

MacOS: 14.3 (23D56)
Xcode version: 15.1 (15C65)

So this is not XCode related issue. This is issue of RealmSwift library.


Another possible workaround is to connect realmSwift as git submodule. I didn't tried it, but I believe that this will work even for latest release.

@anton-plebanovich
Copy link

Well, they switched to library type: .dynamic in the SPM which was not used previously. This mode might be buggy from the Apple side but in any case, it has to be investigated on the RealmSwift side first. There could be a workaround or a solution.

@x-creates x-creates reopened this May 22, 2024
@x-creates
Copy link
Author

from Realm team @nirinchev

We're going to investigate this and see if we can provide a better developer experience here. As a temporary workaround, you can either downgrade to 10.49.2 and copy the entries from the Realm privacy manifest to your app's privacy manifest or consume Realm through non-SPM package manager.

#8588

@zhanswift
Copy link

I've cleaned the DerivedData folder and noticed that the RealmSwift was not embedded.
After I switched to Embed & Sign it is working now.
Screenshot_Realm

@x-creates
Copy link
Author

@austinzheng

I've cleaned the DerivedData folder and noticed that the RealmSwift was not embedded.

Can you please share more details on how you did this?

Did you clean the Derived Data folder, rebuild the project, and then change "Embed & Sign" for it to work?

@zhanswift
Copy link

zhanswift commented Jun 10, 2024

Sure.

  1. Completely close Xcode (CMD+Q)
  2. Run in Terminal: sudo rm -rf ~/Library/Developer/Xcode/DerivedData (Make sure that your Xcode in the Applications folder is named exactly like Xcode)
  3. Open Xcode
  4. Go to Your Project file -> Your app target -> General - > Frameworks, Libraries, and Embedded Content and review this list.
Screenshot_Realm2

@Jeanno
Copy link

Jeanno commented Jun 10, 2024

Well, they switched to library type: .dynamic in the SPM which was not used previously.

Is the option to statically link the library gone? Many "solutions" have the instruction to "embed and sign" RealmSwift but it's not what I want.

@x-creates
Copy link
Author

@zhanswift Thank you for sharing the detailed steps.I don't think I have completed step 2 before. Let me give it a try and see if I can solve this.

@Jeanno I think we can still do it; we just cannot use Swift Package Manager.

@x-creates
Copy link
Author

Quick update. I tried the steps @zhanswift shared above on both the simulator and the physical device, and they seem to work fine. Thanks again for sharing; I really appreciate it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants