hpique
hpique

Reputation: 120324

How to add Private Framework to Target Dependencies?

I'm trying to embed a private framework (last paragraph) in my application bundle using XCode 4 and following Apple's (seemingly) outdated instructions.

In my case, I'm Using Separate Xcode Projects For Each Target. This is the final step:

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. Building the application now builds the framework and copies it to the application bundle directory, creating the necessary linkage between the two.

Yet, when in click on the + button in Target Dependencies the framework doesn't show up. How can I establish a build dependency between the private framework and the application target in Xcode 4?

Edit: I should clarify that I already got the private framework working. I just want to avoid having cleaning the project every time a change to the framework is made, and make sure the framework is built before the application target.

Upvotes: 10

Views: 16698

Answers (5)

us_david
us_david

Reputation: 4917

Here is more complete answer with update for Xcode 12+.

  1. Copy the 3rd party framework to your project folder.
    It can be anywhere within the same project in the tree. You will need the path info in later steps.

  2. In Xcode, select your build target, then select "general" tab, scroll down to "Framework, libraries, and Embedded Content", then select "+" to browse and select the 3rd part library/framework you want to add. See bellow:
    enter image description here

  3. Once added, make sure "Embed & Sign" is selected at the dropdown list for the library/framework you are trying to add.
    This is important since the framework will be looked up and loaded at runtime.

  4. Go to "Build Settings" tab, and find "Framework Search Path", and enter the path to the framework's in relative to your Xcode project file's location. See bellow:
    enter image description here

Now you can build and run your app with the added framework.

Upvotes: 0

Wayne
Wayne

Reputation: 60414

You first need to add the other project's .xcodeproj to the project as a subproject:

  1. Right-click the Frameworks group (or whatever/wherever else)
  2. Select Add Files to "<Project>..."
  3. Select the other project's .xcodeproj
  4. That other project's targets will now appear in the Target Dependencies menu

Upvotes: 1

Rapha&#235;l
Rapha&#235;l

Reputation: 3726

If you want to add your private framework without including it as a sub project, you have to add a Copy Files task for it:

Copy Files task

Select your framework with the + button and choose Frameworks for Destination.

You don't need to add anything in Target Dependencies.

Also for this to work, make sure Runpath Search Paths value is @executable_path/Frameworks in the Build Settings tab.

Upvotes: 2

hpique
hpique

Reputation: 120324

Managed to solve this by adding the private framework project as a subproject, then adding the framework target in Target Dependencies.

However, in my case the framework target didn't show as an option in Target Dependencies until I deleted DerivedData. That nasty little bug drove me crazy.

Upvotes: 12

SRI
SRI

Reputation: 1532

Select your project in the Xcode and then you can find the Project and Target at the right side. Then Select Target and go to LinkBinary with Libraries and then one window will come and there at the bottom left there is an option called Add other.

Upvotes: 0

Related Questions