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

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

Error loading RealmSwift dynamic framework in macOS app #8575

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

Comments

@x-creates
Copy link

x-creates commented May 4, 2024

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.

@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
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

3 participants