6

please take a look at the picture: enter image description here

It's my project structure:

  1. 1 app(top one)
  2. 3 frameworks (create by myself)
  3. 1 cocoa pods static library(bottom one)

When I cmd+b, all the sub projects would be build start from the bottom one to the top one, here is no problem, everything are fine.

  • To refer/link the frameworks, I drop the framework product to every sub project's /Build Phases/Link Binary With Libraries and /Build Phases/Copy Files.

The problem is:

  • When I copy/move the project folder to another place (like ~/oldFolder/app to ~/newFolder/app) the sub project cannot finds the frameworks, it report Not Found Error, I need re-build and drop the framework product to link to fix the error.

It's too stupid and hard to work with other people, anyone can help?

p.s.: sorry for my poor english.

Add error pic: enter image description here

Raymond Liao
  • 1,799
  • 3
  • 20
  • 32

3 Answers3

3

You can use $(SRCROOT) if you want to refer paths relative to your source directory . $(SRCROOT) will point where your project files are . apple doc

An example :

if you have a directory x in your MyApp folder which contains your project file then the folder x can be reffered as $(SRCROOT)/x. Enter this in frameworks path section in Build settings to refer to your library .

MedAmine.Rihane
  • 1,193
  • 10
  • 17
  • The frameworks' build path are default by XCode, so the path are not custom path. You see: Per-configuration Build Products Path=>$(BUILD_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) – Raymond Liao Aug 17 '16 at 08:43
  • hi , you need just to go to the location folder of your framework , Move or copy your framework into your source folder under your project then go to build setting and change path to: $(SRCROOT)/"yourframeworkfoldername" – MedAmine.Rihane Aug 24 '16 at 08:44
  • Sorry for late reply, I accept your answer for my question because you provide a direction for me. Thanks for help. – Raymond Liao Aug 31 '16 at 02:57
  • Thanks :) happy ro help – MedAmine.Rihane Aug 31 '16 at 07:15
1

This all boils down to you not being able to change the location of the already imported frameworks right? This is an example with the FBSDKCoreKit.framework. If I were to change the folder location I would need to change the relative path. Click on the folder Icon right next to the name and choose the new location

enter image description here

tech4242
  • 2,348
  • 2
  • 23
  • 33
  • It's not really. This should be Build Settings issue. I need to know how to setting dynamic refer path of framework in Build Settings. BTW, your sample looks you used the same project structure with mine? Can you share the sample for me? Thanks. – Raymond Liao Aug 24 '16 at 01:45
  • @Raniys Have you tried what I suggested? Anyways another way to tackle this is to remove the framework from Xcode completely and then drag&drop it again with the options "Copy items if needed" and "Add to target" being active. And this is not a template? Unless you mean something else with template. This is an app of mine, which just uses the FBSDKCore & LoginKit – tech4242 Aug 24 '16 at 07:11
  • Yes, your "drag&drop" method is what I did, but I think it is not good. So I want to find another solution to set dynamic path in Build Setting page. Exactly, I need coding the project in my Office and home on different computer, so the "drag&drop" method let me feel sad. – Raymond Liao Aug 25 '16 at 03:48
0

I post the detail of how to fix this issue on my side here:

  • In Framework:
    1. set "$(SRCROOT)/../build" at item "Per-configuration Build Products Path" in Build Setting page;
    2. shift+cmd+k to clean up the framework build, then cmd+b rebuild the framework;
  • In MyApp
    1. add "$(SRCROOT)/../build" at item "Framework Search Path" in Build Setting page;
    2. Drag the framework from the product of framework project to "Link Binary With Libraries" in Build Phases page;
    3. Drag the framework from the product of framework project to "Copy Files" in Build Phases page(you can add the "Copy Files" item by click the top left of Build Phases page);

Please note if you use one more framework in the same project, and the framework also links to another one like the sample I sent in my question, you also need to do all the steps as above I posted(Steps of Framework and App).


Another problem you will meet if you also use cocoapods in your project like my sample: After you done all the steps above, XCode will response error in your framework project like:

ld: framework not found Pods_xxx.framework

clang: error: linker command failed with exit code 1 (use -v to see invocation)

The "xxx" should be your framework project name. To fix it, you just need remove the Pods_xxx.framework in your project/General/Linked Frameworks and Libraries. The error will be disappeared after you rebuild the project. Here you can find the detail of this problem.

p.s.: the Pods_xxx.framework will appear in General/Linked Frameworks and Libraries after you install pod, so you need remove it again if you run command "pod install"

Community
  • 1
  • 1
Raymond Liao
  • 1,799
  • 3
  • 20
  • 32