9

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.

Community
  • 1
  • 1
hpique
  • 119,096
  • 131
  • 338
  • 476
  • Do you have a target for the framework in the project? If not, you're going to have to add one. Target dependencies are for targets. You can't make a single framework a target dependency. – Swift Dev Journal Sep 07 '12 at 17:11
  • No, I don't have a target (see Using Separate Xcode Projects For Each Target in the link). Are you're saying that it's no longer possible to do what the documentation describes? – hpique Sep 07 '12 at 17:19
  • The documentation never said you could make a framework a target dependency. It says you can make a framework target a target dependency. The misleading part of what you quoted is in the first sentence when it says "add your framework as a dependency". It would be clearer if it said "add your framework target as a dependency". Link your framework to the app project as explained in srinaidu's answer. – Swift Dev Journal Sep 07 '12 at 19:49
  • 1
    Yes, adding the framework target as a dependency is exactly what I want to do. @srinaidu is repeating one of the previous steps. It's not what I asked. I already got the linkage working, now I want to solve the dependency. – hpique Sep 07 '12 at 20:04
  • Add a framework target to the project. After adding the framework target, you should be able to make it a dependency of the app target. – Swift Dev Journal Sep 07 '12 at 20:12
  • 1
    I have separate Xcode projects for each target. – hpique Sep 07 '12 at 20:25
  • You could try creating a workspace, place your projects in it, and see if that lets you add the target dependency. If you create a workspace, open the scheme editor and see if it lets you build your framework project before the app project. If that doesn't work, you're going to have to add a target to your app project for the framework. – Swift Dev Journal Sep 07 '12 at 20:40
  • 1
    I have a workspace. I tried both using separate projects and subprojects. Neither option shows up in Target Dependencies. – hpique Sep 07 '12 at 23:55
  • How do you add a target to another target in another project? Is that what you mean? I also tried with aggregate targets but they only work with the targets of the same project. – hpique Sep 08 '12 at 00:03
  • check out Tomte's answer, it works fine: http://stackoverflow.com/a/22608840/4443315 – BoygeniusDexter Aug 12 '16 at 15:28

5 Answers5

12

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.

hpique
  • 119,096
  • 131
  • 338
  • 476
  • I just closed the workspace and reopened it and was then able to add the target as a dependency. Here is a good tutorial on the process: http://pymatics.com/2011/12/23/tutorial-develop-a-private-framework-for-your-mac-app-using-xcode-4s-workspace-feature – GTAE86 Oct 08 '12 at 16:19
  • you need both. Although Xcode resolves dependencies automatically these days, it'll be good for others who browse your project to KNOW that your App depends on its Private framework. – Motti Shneor Feb 14 '16 at 08:30
  • The key here is to add the private framework project as a subproject, after which the private framework's targets will appear in the `Target Dependencies` menu. – Wayne Aug 16 '18 at 14:42
2

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.

Raphaël
  • 3,646
  • 27
  • 28
0

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.

SRI
  • 1,514
  • 21
  • 39
  • That is a previous step and without it the framework wouldn't work. I already got the framework working. Now I want to make sure the framework is built before the application target. – hpique Sep 07 '12 at 20:00
0

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
Wayne
  • 59,728
  • 15
  • 131
  • 126
0

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.

us_david
  • 4,431
  • 35
  • 29