dyld: Library not loaded: @rpath/someframework.framework/someframework

I've been on this problem for weeks so far, searched all the forum and seems it's a common problem as I found a lot of similar questions. Some of them are already resolved, but others are still open. Here you are a detailed description of my issue:


I'm working on a Swift project (Swift 2.1) that references multiple objective c projects and frameworks written in objective c. The problem actually happens because of one of the frameworks "DTRichTextEditor" which is an open source project used to render attributed string. This framework has deep dependencies of other frameworks that all included in my project as a tree of projects (3 levels). The following may emphasize the dependency tree:


MyProject

|

- GlimpseXML (Xcode project in Swift) (No problem here)

|

- DTRichTextEditor (XCode project in Objective C packaged in a framework DTRichTextEditor.framework) (This dependency tree causes the issue)

|

- DTCoreText (XCode project in Objective C packaged in a framework DTCoreText.framework)

|

- DTFoundation (XCode project in Objective C packaged in a framework DTFoundation.framework)

|

- DTLoupe (XCode project in Objective C packaged in a dynamic library libDTLoupe.a)

|

- DTWebArchive (XCode project in Objective C packaged in a dynamic library libDTWebArchive.a)


The dependencies of projects is set properly: DTFoundation is a dependency for DTCoreText, DTCoreText is dependency for DTRichTextEditor.

The app works fine on the simulator, but when I deploy to debug on the device, it crashes instantly with the following log:


dyld: Library not loaded: @rpath/DTRichTextEditor.framework/DTRichTextEditor

Referenced from: /private/var/mobile/Containers/Bundle/Application/FFCCF915-282C-4EEA-8103-619B0E2E7360/appname.app/appname

Reason: image not found


dyld`dyld_fatal_error:
->  0x1200e9088 <+0>: brk    #0x3


Other times, the crash comes from DTCoreText instead of DTRichTextEditor! seems there's inconsistency in the crashing behaviour.


I already added all the aforementioned frameworks to the "Embedded frameworks" & "Linked Frameworks and Libraries" in the General tab of the target settings.

Obviously the embedded frameworks are not deployed and embedded to the app package such that when the app launches, the framework binary is missing!


Development environment:

OS: El Capitan 10.11.1

Machine: MacBook Pro (15-inch late 2011), 16 GB memory

Deployment Target: 8.0

Deployment device OS: many iPads with iOS 8.1+


I've tried the following:

1) Restarting the XCode & the machine.

2) Cleaning Whole projects and rebuilding.

3) Deleting Derived Data.

4) Switching "Embedded Content Contains Swift" on & off.

5) Revoking my developer certificate and resetting the provisioning profiles.

6) Reinstalling the WWDR certificate.

7) Reinstalling all certificates in keychain & changing the Trust option to "Always Trust" and "Use System Defaults".

8) Switching Enable Bitcode on & off.

9) Including the frameworks in second level and deeper as direct dependents of the main project such that the dependency tree looks like:

MyProject

|

- GlimpseXML (Xcode project in Swift) (No problem here)

|

- DTCoreText (XCode project in Objective C packaged in a framework DTCoreText.framework)

|

- DTFoundation (XCode project in Objective C packaged in a framework DTFoundation.framework)

|

- DTLoupe (XCode project in Objective C packaged in a dynamic library libDTLoupe.a)

|

- DTWebArchive (XCode project in Objective C packaged in a dynamic library libDTWebArchive.a)

|

- DTRichTextEditor (XCode project in Objective C packaged in a framework DTRichTextEditor.framework) (This dependency tree causes the issue)

|

- DTCoreText (XCode project in Objective C packaged in a framework DTCoreText.framework)

|

- DTFoundation (XCode project in Objective C packaged in a framework DTFoundation.framework)

|

- DTLoupe (XCode project in Objective C packaged in a dynamic library libDTLoupe.a)

|

- DTWebArchive (XCode project in Objective C packaged in a dynamic library libDTWebArchive.a)

This is in case there is a problem with embedding deep framework trees in the main binary.

10) Compiling every framework independently and including them manually in a lib/ directory in the app & as embedded frameworks. Same problem occurs!

11) Setting the Runpath search paths to "@executable_path/Frameworks" & "$(PROJECT_DIR)/lib/$(CONFIGURATION)" in case the frameworks are added manually to the project.


Any advice is apprciated so much?

Accepted Reply

Eventually and after 3-months struggle, I solve it following the instructions in this document

https://developer.apple.com/legacy/library/technotes/tn2250/_index.html#//apple_ref/doc/uid/DTS40009933-CH1-TNTAG19

Replies

Eventually and after 3-months struggle, I solve it following the instructions in this document

https://developer.apple.com/legacy/library/technotes/tn2250/_index.html#//apple_ref/doc/uid/DTS40009933-CH1-TNTAG19

My app includes some dynamic Frameworks. All of them are loaded by the dlopen function at runtime. However, I found it would be failure at rate of 0.02%.

There are two kindles of errors. The most one shows that `the file does not exist`. Another one shows that `the dlopen function call failed`.

So, my questions are followings:

1. Would dynamic library files or picture files be lost when App downloading from AppStore?

2. Would the missing files affect the installation of App?

3. Which files are necessary to install applications and which ones are not?

4. What could I improve the rate of loading dynamic libraries successful at runtime?