11

I am trying to embed a Framework that are using another Framework and this works just fine in the simulator, but it crashes on an iOS device:

dyld: Library not loaded: @rpath/FrameworkB.framework/FrameworkB Referenced from: /private/var/mobile/Containers/Bundle/Application/B072CD7C-8595-4AE4-A506-26832A0F4402/FrameworkTest.app/Frameworks/FrameworkA.framework/FrameworkA Reason: image not found

This is my structure in Xcode:

  • FrameworkTest.xcodeproj (the app project)
    • FrameworkA.xcodeproj (Cocoa Touch Framework)
      • FrameworkB.xcodeproj (Cocoa Touch Framework)

The app (FrameworkTest) uses a class A from FrameworkA (which is embedded in the FrameworkTest app). The class A uses the class B from FrameworkB (which is linked in FrameworkA).

This works just fine in the simulator, but it does not work on the device.

The structure may seem a bit strange, but I am developing the frameworks as I go when I develop the app, which is why I want to add the framework projects inside my app project.

I have uploaded the project on GitHub for you to see, if you need to take a closer look. (The class A is invoked in the AppDelegate.m file)

Why is this working in the iOS simulator and not on the device? And how can I make it work on the device?

EDIT:

As simonthumper suggests in the comments, I have also tried to add FrameworkB.framework to Copy Files as Frameworks destination in Build Phases for FrameworkA, but that gives me this error in the console:

dyld: Library not loaded: @rpath/FrameworkB.framework/FrameworkB Referenced from: /private/var/mobile/Containers/Bundle/Application/2A38A2BC-9CD7-4AF6-9E50-42C16D92D6B2/FrameworkTest.app/Frameworks/FrameworkA.framework/FrameworkA Reason: no suitable image found. Did find: /private/var/mobile/Containers/Bundle/Application/2A38A2BC-9CD7-4AF6-9E50-42C16D92D6B2/FrameworkTest.app/Frameworks/FrameworkA.framework/Frameworks/FrameworkB.framework/FrameworkB: mmap() error 1 at address=0x10012C000, size=0x00008000 segment=__TEXT in Segment::map() mapping /private/var/mobile/Containers/Bundle/Application/2A38A2BC-9CD7-4AF6-9E50-42C16D92D6B2/FrameworkTest.app/Frameworks/FrameworkA.framework/Frameworks/FrameworkB.framework/FrameworkB

ThomasCle
  • 6,792
  • 7
  • 41
  • 81

2 Answers2

15

I contacted Apple with this issue and found a solution to my problem. Apple's Technical support made it clear, that I need to add the FrameworkB.xcodeproj to my application project, so my project structure is:

  • FrameworkTest.xcodeproj (the app project)
    • FrameworkA.xcodeproj (Cocoa Touch Framework)
      • FrameworkB.xcodeproj (Cocoa Touch Framework)
    • FrameworkB.xcodeproj (Cocoa Touch Framework)

When I have done this the application project can include FrameworkB.framework as an Embedded Library: FrameworkTest.xcodeproj build phases

This solved my problem and made it possible to run it on an iOS device.

If the build crashes on Release: Revoke your Enterprise Distribution certificate and create a new one to solve the problem. Once I did that it worked perfectly.

ThomasCle
  • 6,792
  • 7
  • 41
  • 81
  • Hi. I am also facing same kind of issue. But i don't have second framework project code with me (only FrameworkB.framework i have). Any idea how do i go about it ? – EXC_BAD_ACCESS Mar 10 '16 at 09:31
  • +1 But this shouldn't be a solution - how can we build single-file SDKs if so :-( Any updates to the situation as of date? – Angad Jun 28 '16 at 14:52
  • Solved my issue, thanks. Anyhow, are we not adding frameworkB twice? I would compare with a solution in which it is not added (allegedly) twice, but I don't have it... Or is Xcode intelligent enough to add it only once? I'd like to believe that since they are frameworks (dynamic shared libraries, right?), the first time frameworkB is added to frameworkA, only the reference is copied. However, when frameworkB is added to frameworkTest, the code is copied, not the reference. Am I right? Someone point me in the right direction to understand this, please :) – inigo333 Sep 09 '16 at 09:27
6

I also had similar issues with embedded frameworks and I just tried your code from GitHub.

Option 1 (not suitable for teamwork)

What made the error disappear was to add FrameworkB to Embedded Binaries in the General tab of your FrameworkTest target.xcode - embedded binaries

Option 2

Well, sharing project with other developers sure is important :). Did you try this approach? Add New Copy Files Phase In the FramewrokA's Build Phases and add FrameworkB into Frameworks destination. new copy phase

But I'm not sure why does it work on the simulator. If anyone knows, please, feel free to comment.

cheers

micromanc3r
  • 569
  • 1
  • 8
  • 16
  • Thanks, but I have tried adding FrameworkB to Embedded Binaries too, and that works. But it links directly to the `DerivedData` directory, which isn't what I am after. This will only work on your Mac. I am sharing the project with other developers, so this needs to work without any specific paths. :-) – ThomasCle Mar 02 '15 at 07:09
  • @ThomasClemensen I just read your edit so my second solution is bad for you as well ...but it did work for me (using your project) – micromanc3r Mar 02 '15 at 20:17
  • @micromanc3r I've tried your second Option 2 but this giving me error. dyld: Library not loaded: @rpath/FrameworkB.framework/FrameworkB Referenced from: ......FrameworkTest.app/Frameworks/FrameworkA.framework/FrameworkA Reason: no suitable image found. Did find: .....FrameworkTest.app/Frameworks/FrameworkA.framework/Frameworks/FrameworkB.framework/FrameworkB' – Aleem May 17 '18 at 08:06
  • Option 2 is awesome compared to "embed swift standard library" option in other answers regarding that kind of problem – Tancrede Chazallet Aug 06 '18 at 13:21