Thomas Clemensen Thomas Clemensen - 29 days ago 14
iOS Question

dyld: Library not loaded for a Framework within a Framework

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

Answer

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.

Comments