Workspace-based app/framework embed fails to build
| Originator: | matt | ||
| Number: | rdar://19676587 | Date Originated: | 1/31/2015 |
| Status: | Open | Resolved: | |
| Product: | Developer Tools | Product Version: | Xcode 6.2 (6C107a) / OS X 10.10.2 (14C109) |
| Classification: | Serious Bug | Reproducible: | Always |
Summary:
The WWDC14 video on iOS 8 frameworks recommends single-project, multiple target workflows for app-framework bundles, but that of course isn't possible for so many distributed projects that use multiple internal and external (FOSS/GitHub/etc) repositories. This bug details one of a few problems when trying to replicate framework embed builds using a multi-project workspace.
The Xcode build system creates a false/incorrect file reference when attempting to add a framework from one project to an app in another project, but in the same workspace. The result is a series of build failures/warnings.
Steps to Reproduce:
1. Create a "Single View App" iOS template, App.xcodeproj
2. Create a "Cocoa Touch Framework" template, Framework.xcodeproj
3. Create a Workspace, e.g. Workspace.xcworkspace
4. Drag the two xcodeproj's into the workspace.
5. Select the App project from the workspace window, and go to the General settings for the App target.
6. Add Framework.framework to Linked Frameworks and Libraries in the App target's General settings. It should appear under "Workspace" in the "Choose frameworks and libraries to add:" sheet that shows when hitting the + button.
7. In the same General settings for the App target, now go to Embedded Binaries and add the Framework.framework file reference listed under the App project. (This seems a bit roundabout; see rdar://19676555)
8. Build the App scheme (device or simulator, doesn't matter)
Expected Results:
Actual Results:
Two bad/odd things should have happened by now:
Problem 1: A second reference to the framework is added to Linked Frameworks and Libraries after step 7 (see FrameworkParty.png)
Problem 2,3: Building the App scheme now fails with an error and a warning that appear to be symptoms of the same problem:
ld: warning: directory not found for option '-F/tmp/WorkspaceTest/Framework/build/Debug-iphoneos'
error: /private/tmp/WorkspaceTest/Framework/build/Debug-iphoneos/Framework.framework: No such file or directory
It appears the Framework.framework reference in App.xcodeproj is specific/relative to an assumed output of the owning project, Framework.xcodeproj, instead of the workspace (see FrameworkFileReferencePath.png). Changing the "relative to" setting on the file reference doesn't change anything (see RelBuildProducts.png) because the presumed path is wrong in the first place.
Inspecting App.xcodeproj/project.pbxproj reveals the following:
6DFC454D1A7D615400C7779A /* Framework.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Framework.framework; path = "../Framework/build/Debug-iphoneos/Framework.framework"; sourceTree = "<group>"; };
In reality, this should be nothing more than Framework.framework under BUILT_PRODUCTS_DIR or similar, e.g. ~/Library/Developer/Xcode/DerivedData/Workspace-bbiclmbeggbudrfjuzweloobycfh/Build/Products/Debug-iphonesimulator/Framework.framework. The only way I have been able to properly fix this is to hand-hack App.xcodeproj/project.pbxproj along those lines (note all the subdirectories removed):
6DFC454D1A7D615400C7779A /* Framework.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Framework.framework; path = "Framework.framework"; sourceTree = BUILT_PRODUCTS_DIR; };
Making this change in a text editor and reloading the project fixes everything.
Version:
Xcode 6.2 (6C107a) / OS X 10.10.2 (14C109)
Notes:
Searching for "Embedded Binaries" in the Xcode doc window returns zero results. Searching the internet returns a bunch of misguided Stack Overflow threads that I won't bother linking to here. As far as I can tell, there is zero guidance on how to do this right, so I can't tell if this is a bug(s) or if I'm just Doing It Wrong™.
I suppose this is technically two or three different bugs:
1) Bad framework reference path
2) Duplicate Linked Libraries add
3) Unnecessary append to Framework Search Paths
but they are part of the same sequence, so I'm logging them together.
It's much better if you perform these steps yourself to see how awkward the flow is, but for technical / state reference, you can download or checkout the WorkspaceEmbed branch of my radars repo on GitHub:
https://github.com/drance/radars/tree/WorkspaceEmbed
It has both Broken and Fixed variants for easy diffing of the two App.xcodeproj/project.pbxproj files (the only file that needs to be changed.)
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!