11
votes

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

2
Have you got the framework in the copy files build phase?simonthumper
@simonthumper I have edited the question with more information if I do that :-)ThomasCle
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

2 Answers

14
votes

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.

5
votes

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