Xcode Project with Framework - Library not loaded - mapping process and mapped file have different Team IDs

I am starting a new Xcode Project for macOS app. During the initial development I found that some part of the app should be shared between different targets like macOS App, Quick Look etc. The goal was to user Framework. By selecting Project in Project navigator and using the plus icon, I have created a new Framework target and called it Shared.

Next, in my App Project I have added it into the project and checked if it is correctly linked. The framework was Embedded and Signed. Both targets have the same Signing & Capabilities settings.

After I move a code into Shared framework it was time for first run. Unfortunately, the app is crashing instantly, and I am getting the error:

dyld[65044]: Library not loaded: @rpath/Shared.framework/Versions/A/Shared
Referenced from: 
<2B03FB61-86B3-31E5-A2A4-F18F43AEC875> /Users/{User}/Library/Developer/Xcode/DerivedData/AppName-fjfbylcqrxaiobgohprplbaohgbw/Build/Products/Debug/AppName e.app/Contents/MacOS/AppName

Reason: tried: 
'/Users/{User}/Library/Developer/Xcode/DerivedData/AppName-fjfbylcqrxaiobgohprplbaohgbw/Build/Products/Debug/Shared.framework/Versions/A/Shared' 
(code signature in <DD201FE7-57E2-33B1-AD7C-E61BA1345673> '/Users/{User}/Library/Developer/Xcode/DerivedData/AppName-fjfbylcqrxaiobgohprplbaohgbw/Build/Products/Debug/Shared.framework/Versions/A/Shared' 

not valid for use in process: mapping process and mapped file (non-platform) have different Team IDs), 

'/Users/{User}/Library/Developer/Xcode/DerivedData/AppName-fjfbylcqrxaiobgohprplbaohgbw/Build/Products/Debug/AppName.app/Contents/Frameworks/Shared.framework/Versions/A/Shared' 

(code signature in <DD201FE7-57E2-33B1-AD7C-E61BA1345673> '/Users/{User}/Library/Developer/Xcode/DerivedData/AppName-fjfbylcqrxaiobgohprplbaohgbw/Build/Products/Debug/AppName.app/Contents/Frameworks/Shared.framework/Versions/A/Shared' 

not valid for use in process: mapping process and mapped file (non-platform) have different Team IDs), 

'/Users/{User}/Library/Developer/Xcode/DerivedData/AppName-fjfbylcqrxaiobgohprplbaohgbw/Build/Products/Debug/AppName.app/Contents/Frameworks/Shared.framework/Versions/A/Shared' 

(code signature in <DD201FE7-57E2-33B1-AD7C-E61BA1345673> 

'/Users/{User}/Library/Developer/Xcode/DerivedData/AppName-fjfbylcqrxaiobgohprplbaohgbw/Build/Products/Debug/AppName.app/Contents/Frameworks/Shared.framework/Versions/A/Shared' 

not valid for use in process: mapping process and mapped file (non-platform) have different Team IDs)

The Team ID is set properly in Build Settings for both targets. The Bundle Identifier is different and the rest of the settings seems to be correct. I tried changing and juggling the settings related to signing the framework, but it didn't help.

I am totally lost without any other idea to fix it... I will be glad for some help.

I found this topic while trying to solve pretty much the same issue in my project, and since I've found a solution, I was thinking to share it in case it would help someone else in the same situation.

Turns out the framework in the build folder is not signed, so it couldn't be loaded properly. At the same time the framework located in the resulted application bundle is signed properly, but it was not used for some reason. You can check the signature of the framework with codesign -d -r - Shared.framework command.

I was able to solve the issue by adding following properties to the build settings, hope it will help someone

LD_RUNPATH_SEARCH_PATHS = @executable_path/Frameworks
LD_RUNPATH_SEARCH_PATHS[sdk=macosx*] = @executable_path/../Frameworks

Essentially it loads frameworks from the expected location for the iOS build and the other location for the macOS build (the bundle structure is different depending on the destination).

Xcode Project with Framework - Library not loaded - mapping process and mapped file have different Team IDs
 
 
Q