Xcode10 - Dyld: Library Not Loaded for Pod Installed in Framework

Xcode10 - dyld: Library not loaded for pod installed in framework

From your error message, there are a few things that should be checked.

dyld: Library not loaded: @rpath/PodA.framework/PodA
Referenced from: .../Build/Products/Development-iphonesimulator/FrameworkA.framework/FrameworkA
Reason: image not found

The first thing that seems odd is that the path for the framework that is being loaded (FrameworkA.framework) is not embedded inside an app. Check the "General" tab of the MainAppTarget and make sure the framework is appearing in the "Embedded Binaries" and "Linked Frameworks and Libraries" sections.

Second, @rpath is a shorthand for the runpath search path list, which tells dyld where to look for needed libraries.

Here's an example project on Github with a main app that uses one Cocoapod, and a dynamic framework that the main app depends on that uses a different Cocoapod: https://github.com/dtweston/FrameworkPodTest

Build settings that you should check on all of the targets that are involved (including the framework targets built by the Pods project):

  • Runpath Search Paths (LD_RUNPATH_SEARCH_PATHS)

    • In the example project, these are determined by the cocoapod, but each one is set to $(inherited) @executable_path/Frameworks @loader_path/Frameworks
  • Dynamic Library Install Name (LD_DYLIB_INSTALL_NAME)

    • In the example project, this is unchanged from the default $(DYLIB_INSTALL_NAME_BASE:standardizepath)/$(EXECUTABLE_PATH)
  • Dynamic Library Install Name Base (DYLIB_INSTALL_NAME_BASE)

    • In the example project, set to @rpath (again determined by the Cocoapod)

Here's a screenshot of the built application bundle showing how it's laid out:
Finder window

You can use otool to get information about how the application is assembled by xcodebuild.

Here's the main app binary:

otool -L FrameworkPodTest
FrameworkPodTest:
@rpath/KeychainSwift.framework/KeychainSwift (compatibility version 1.0.0, current version 1.0.0)
@rpath/Lottie.framework/Lottie (compatibility version 1.0.0, current version 1.0.0)
/System/Library/Frameworks/UIKit.framework/UIKit (compatibility version 1.0.0, current version 61000.0.0)
@rpath/Framework.framework/Framework (compatibility version 1.0.0, current version 1.0.0)
/System/Library/Frameworks/Foundation.framework/Foundation (compatibility version 300.0.0, current version 1560.10.0)
/usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 228.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1252.200.5)
/System/Library/Frameworks/CoreGraphics.framework/CoreGraphics (compatibility version 64.0.0, current version 1245.9.2)
...

And the framework binary:

otool -L Frameworks/Framework.framework/Framework
Frameworks/Framework.framework/Framework:
@rpath/Framework.framework/Framework (compatibility version 1.0.0, current version 1.0.0)
@rpath/KeychainSwift.framework/KeychainSwift (compatibility version 1.0.0, current version 1.0.0)
/System/Library/Frameworks/Foundation.framework/Foundation (compatibility version 300.0.0, current version 1560.10.0)
/usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 228.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1252.200.5)
@rpath/libswiftCore.dylib (compatibility version 1.0.0, current version 1000.11.42)
@rpath/libswiftCoreFoundation.dylib (compatibility version 1.0.0, current version 1000.11.42)
...

Cocoapods dependency and Library not loaded ... image not found

Looks like the issue was due to the default setting of "per-configuration build products path" which was $PODS_SHARED_BUILD_DIR/Alamofire, which was conflicting where the project thought the framework should be (the framework was pointing to another path). Changing the value to simply be $PODS_SHARED_BUILD_DIR solved the build issue, since the two locations ended up being the same.

Before this I had not done anything else than pod install and a build of the workspace.

Note, once I solved that issue I did need to add the following path to the "runtime search paths":

/System/Library/CoreServices/MRT.app/Contents/Frameworks/

Appears to be covered by issue #4963

CocoaPods integration problems: dyld: Library not loaded: @rpath/Bolts.framework/Bolts

I've solved it! I tried everything but then I remember that the problem should also be the certificate signing my project and I run this lines in the terminal:

rm -rf "$(getconf DARWIN_USER_CACHE_DIR)/org.llvm.clang/ModuleCache"
rm -rf ~/Library/Developer/Xcode/DerivedData
rm -rf ~/Library/Caches/com.apple.dt.Xcode

This worked and the app is running right now on my device!

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

I didn't stop figuring out the cause of the issue until I read about architectures. So it prompted me to build the frameworks while an iPhone 6 is connected. I created a project with all the defaults. Added a couple of frameworks including Alamofire. Built them while iPhone 6 connected. Generated an archive and deployed and installed OTA. When the app was installed it ran without issues.

I tried to confirm it by building against my iPod(MD717ZP/A). I'm not sure if this was 5th Gen. First I emptied the derived data folder, Cleaned all projects including the frameworks. Built and deployed the app. Installed it on the iPod it was running. I installed it on the iPhone 6 and it crashed instantly.

I tried the same process over and over again. Built against iPhone 6 then iPod then installed on both. The results just confirmed that I need to have it built on iPhone 6 so the app would run on that device and lower.

Remember I ONLY did add the frameworks to "Embedded Binaries" (Target > General > Embedded Binaries) then built on iPhone 6 to make it work. This could mean you need to have the latest device if you want it running on all devices due to some architecture requirements.

Update:
In addition to the knowledge above you may want to check the "Build Active Architecture Only" section in the Build Settings tab. It means it will build based on the connected hardware if set to YES else it will build for the architectures you support like Valid Architectures.



Related Topics



Leave a reply



Submit