Problems with Workspace containing two iOS Projects and a shared Framework

This seems like it should be simple, but it doesn't seem to work properly... there are a lot of guides out there, and some of them get insanely complicated involving writing shell scripts, which doesn't seem like it should be right.


I have an XCode Workspace containing two iOS Projects and a shared Framework that they both should use.


To set this up:

  • In the iOS Project Targets General tab,
  • under Linked Frameworks and Libraries,
  • I press +,
  • and select the framework, which is listed under Workspace rather than iOS 9.2.


This has a number of automatic effects on the project:

  • The framework appears in that section, marked as Required
  • In Build Settings:
    • Runpath Search Paths is set to @executable_path/Frameworks
    • Framework Search Paths is set to $(PROJECT_DIR)/build/Debug-iphoneos (it shows the full path, but revealing shows this)
  • In Build Phases:

    Link Binary with Libraries shows the Framework

  • In the iOS Project itself, the Framework appears as a red member:
    • Location is set to Relative to Group,
    • and the path is build/Debug-iphoneos/DungeonKit.framework


When I Run the project, I get a warning:


Ld /Users/scott/Library/Developer/Xcode/DerivedData/DungeonMaster-aryikklnhzulpzexkhjnqpakqtos/Build/Products/Debug-iphonesimulator/DungeonMaster.app/DungeonMaster normal x86_64
    cd /Users/scott/Developer/DungeonMaster
    export IPHONEOS_DEPLOYMENT_TARGET=9.2
    export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.2.sdk -L/Users/scott/Library/Developer/Xcode/DerivedData/DungeonMaster-aryikklnhzulpzexkhjnqpakqtos/Build/Products/Debug-iphonesimulator -F/Users/scott/Library/Developer/Xcode/DerivedData/DungeonMaster-aryikklnhzulpzexkhjnqpakqtos/Build/Products/Debug-iphonesimulator -F/Users/scott/Developer/DungeonMaster/build/Debug-iphoneos -filelist /Users/scott/Library/Developer/Xcode/DerivedData/DungeonMaster-aryikklnhzulpzexkhjnqpakqtos/Build/Intermediates/DungeonMaster.build/Debug-iphonesimulator/DungeonMaster.build/Objects-normal/x86_64/DungeonMaster.LinkFileList -Xlinker -rpath -Xlinker @executable_path/Frameworks -mios-simulator-version-min=9.2 -Xlinker -objc_abi_version -Xlinker 2 -L/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator -Xlinker -add_ast_path -Xlinker /Users/scott/Library/Developer/Xcode/DerivedData/DungeonMaster-aryikklnhzulpzexkhjnqpakqtos/Build/Intermediates/DungeonMaster.build/Debug-iphonesimulator/DungeonMaster.build/Objects-normal/x86_64/DungeonMaster.swiftmodule -framework DungeonKit -Xlinker -dependency_info -Xlinker /Users/scott/Library/Developer/Xcode/DerivedData/DungeonMaster-aryikklnhzulpzexkhjnqpakqtos/Build/Intermediates/DungeonMaster.build/Debug-iphonesimulator/DungeonMaster.build/Objects-normal/x86_64/DungeonMaster_dependency_info.dat -o /Users/scott/Library/Developer/Xcode/DerivedData/DungeonMaster-aryikklnhzulpzexkhjnqpakqtos/Build/Products/Debug-iphonesimulator/DungeonMaster.app/DungeonMaster
ld: warning: directory not found for option '-F/Users/scott/Developer/DungeonMaster/build/Debug-iphoneos'


The project runs in the simulator just fine when in debugging mode,


but when I try and start the app in the Simulator by hand, it crashes immediately:


Dyld Error Message:
  Library not loaded: @rpath/DungeonKit.framework/DungeonKit
  Referenced from: /Users/USER/Library/Developer/CoreSimulator/Devices/6B0E897B-3DB7-4241-9F91-13E8DCA82974/data/Containers/Bundle/Application/668FD86F-0B44-4C62-9935-FD64F6D95C39/DungeonMaster.app/DungeonMaster
  Reason: image not found


If I try and run the project on an actual iOS device instead, it doesn't even start, and crashes immediately (even with the Xcode debugger):


dyld: Library not loaded: @rpath/DungeonKit.framework/DungeonKit
  Referenced from: /var/mobile/Containers/Bundle/Application/0EA2E7E1-103B-4398-899C-DC7D5F7E01C3/InitiativeOrder.app/InitiativeOrder
  Reason: image not found



Assistance would be appreciated!

Yes, this has been discussed before. It's a limitation of using workspaces. The workaround is to either use a single project with multiple targets or clean when switching platforms.

I'm not sure that it's a limitation, it seems to be a flat-out Xcode bug.


Xcode produces different results before the framework has been built for an iOS device, compared with after.


Xcode also seems to produce difference results depending on whether you embed first, or link first; and even whether you drag, or use "+".


And finally Xcode embeds absolute paths rather than ones relative to the build directory.


I found a way to consistently get this to work: http://netsplit.com/xcode-two-apps-with-a-shared-private-framework-in-a-workspace

Problems with Workspace containing two iOS Projects and a shared Framework
 
 
Q