Xcode Framework Search Paths not finding frameworks outside project directory - xcode

In a large monorepo of Cocoapod projects I have the following directory structure.
Project
Common
Foo.Framework
First Project
Project.Xcode
Second Project
Project.Xcode
The goal is that there are multiple Cocoapod projects and rather than have the same framework copied in multiple places within the First and Second project, I'd rather have it once in a Common folder in the parent directory, and then drag it into the project and set the framework search paths.
So I'm running into an issue where the linker cannot find the Foo.framework.
What should I set the framework search path to so that it correctly finds the framework.
If I include the framework inside the Project directories it doesn't run into any issues.

I had the same issue and solved it like following:
Go to Build Settings
Find the "Framework Search Paths"
Add $(PROJECT_DIR)/../your_directory
Use the recursive flag if the framework file isn't in the exact directory you selected)

Related

How do you reference the git repository root directory in Xcode build settings?

How do you reference the git repository root directory in Xcode build settings?
We have a project where our original source code comprises 39 modules (framework targets) spread around in various levels of subdirectories.
In addition we keep certain modules like Crashlytics in the repository root in a folder called "ThirdPartyFrameworks" and then we have "Carthage" also at the repository root.
Currently each framework references all third party dependencies through paths relative to each framework's project directory, e.g. $(PROJECT_DIR)/../../../Carthage/Build/iOS etc. However, if you want to reorganize the project, and move a project to a new spot, then all these kinds of links will break, since they're relative.
What I would greatly prefer to do is just have one shared config file that references these framework search paths like: $(GIT_ROOT)/Carthage and be done with it. However I don't see any way to reference the repo root or workspace root that way.
Does anyone know a way to do this...? Thanks.

Setting up sample project for other developers Xcode

So I am trying to set up a sample project that includes all of the search headers for distributing to other developers.
My plan is to have the folder structure something like this when the developer unzips the project:
/SDKandSample
/SDKandSample/SDK
/SDKandSample/SampleProject
How can I have xcode link to the correct SDK folder regardless of where the folder is stored?
You can set up a workspace that includes two projects. One project is your framework / library. And the other is your example project. The example project will link to your framework / library. Check out this project for an example.
If you're wondering how to create file paths in build settings that reference the project root:
$(SRCROOT)/MyDirectory/MyFile.ext

Cocoapods generating separate additional workspace project file?

Somewhat of an intrigue to me is how Xcode creates a new workspace project file after you make your project 'cocoapods aware' to install a pod to your current project. So the older project file has blue icon, the new one has the same name but with .workspace appended and has white icon.
I am wondering why the need to have this separate file and also if the older one without the pod is still needed by this new file?
A workspace is an Xcode document that groups projects and other
documents so you can work on them together. A workspace can contain
any number of Xcode projects, plus any other files you want to
include. In addition to organizing all the files in each Xcode
project, a workspace provides implicit and explicit relationships
among the included projects and their targets.
Since Cocoapods is a library manager and install/integrate all the libraries you want in your project. After installing pods, you have noticed that it creates a workspace that contain your project + Pods Project (this one contain all the libraries that you have installed.) as your project has dependencies on those libraries and this is how CocoaPods works. You can open your project with older name '.xcodeproject' but you won't be able to access the libraries as it does not contain pod.

Target dependencies vs. Link binary with libraries

I don't understand the difference between these Xcode features.
I'm building and app - but the functionality of the app is being abstracted into libraries (so they can be distributed separately as an "SDK").
So I have a workspace of library projects and the app project. I can add library projects to the app project by doing "link binary with libraries". This gives me a list of .a library projects in the current workspace which I can link to.
I can also add frameworks here.
In the "target dependencies" bit all I can add is other targets in the current project.
What I really want to do is both - I want my app project to build all the other library projects when I build it. I also want to make it verbose what libraries the app (and other libraries) depend on.
So can somebody please explain the difference, and whether what I am doing is the right way to go about it?
Many thanks!
It says here...
Drag your framework product (located in the Products folder) to the existing Link Binary With Libraries build phase of your application
target. This causes the application to link against your framework.
And...
In the General tab of the inspector window, add your framework as a dependency for the application. Adding this dependency causes Xcode to
build the framework target before building the application target.
The build dependency you establish in the application target causes
the framework to be built before the application. This is important
because it guarantees that a built version of your framework will be
available to link against and to embed in the application. Because of
this dependency, you can set the active target of your Xcode project
to your application and leave it there.
So it seems that you're supposed to use both. Seems redundant though, because if you're linking to a framework then its a dependency. I suppose you might want to only link to a library and not build it first. Although Xcode seems to build linked libraries even without them being added to the dependency section. Perhaps that's a result of the "Find Implicit Dependencies" option in a scheme's build settings.
I do something similar and was explicitly setting the 'header search path' and 'library search path' in the final executable target. However this all depended on where the objects were being generated. Initially I had set this to be within the source tree (actually a sibling directory called build), however after changing the location of the Xcode DerivedData directory and telling it to build into that directory, the projects no longer built.
The final solution was simply to remove the explicit setting of the 'header/library search path' and set the target dependencies correctly. This resulted in the project building for debugging and archiving without issue.

How to import JSON framework?

I've downloaded the JSON framework DMG from http://code.google.com/p/json-framework/downloads/list. I followed Option 3 here: http://code.google.com/p/json-framework/wiki/InstallationInstructions. For the copy files build phase, I set path to ~/Library/Frameworks/JSON.framework. Buid failed. I then tried setting it to my project root. Build failed.
I keep getting this error:
<JSON/JSON.h>: No such file or directory
Any suggestions?
There's no need to put the framework in Library, at least under Xcode 3.1.3. Here's what you do:
Put the JSON framework source tree in your source tree.
Add the framework project to your project.
Get Info on your target, click + under the Direct Dependencies list, and choose the framework target from the framework project.
Right-click on your target in the group tree and choose “New Build Phase▶ Copy Files”. In the window that results, choose Frameworks as the destination.
Add the framework target (which will transmogrify into its build product) to the Copy Files phase.
Add the framework target (which will transmogrify) to your target's Link with Libraries phase.

Resources