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:
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
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:
When I have done this the application project can include FrameworkB.framework as an Embedded Library:
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.
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.
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.
But I'm not sure why does it work on the simulator. If anyone knows, please, feel free to comment.
cheers
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With