Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
186 views
in Technique[技术] by (71.8m points)

ios - 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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...