-->

OS X Framework Library not loaded: 'Image not

2019-01-02 19:54发布

问题:

I am trying to create a basic OS X Framework, right now I just have a test framework created: TestMacFramework.framework and I'm trying to import it into a brand new OS X Application project.

I have built the .framework file and imported it into the new project, The framework appears to link okay, and I can reference the public header file I added to the framework build phases section.

However, when I try to run the container Application I get the following Error:

dyld: Library not loaded: /Library/Frameworks/TestMacFramework.framework/Versions/A/TestMacFramework
  Referenced from: /Users/samharman/Library/Developer/Xcode/DerivedData/TestMacContainer-dzabuelobzfknafuhmgooqhqrgzl/Build/Products/Debug/TestMacContainer.app/Contents/MacOS/TestMacContainer
  Reason: image not found

After a bit of googling I realised I needed to add a Copy Files section to my container application build phases, so I have done this and set it up like so...

However, I am still getting the runtime error. I'm obviously doing something wrong here, but the Apple developer library resource for this references Xcode 2, so isn't very helpful!

What have I missed?

UPDATE:

I can see in the build log that my TestMacFramework.framework is being copied into the .app contents/frameworks directory, but it isn't being installed to the Library/Frameworks directory on the HD

UPDATE 2:

The build links correctly if I manually copy the TestMacFramework.framework into the Library/Frameworks directory

回答1:

[from Xcode 6 -> 7.3]

(Yes, still working on Xcode 10, iOS and macOS)

The only thing to do is to add the framework to the Embedded binaries section in the General tab of your app target.



回答2:

So I managed to get it working, it's quite simple when you have the right instructions. What I was looking for was a 'private' framework which lives in the App bundle rather than being written to the system library folder.

Building The Framework

  1. Add a target to create a Cocoa Framework
  2. Within that targets 'Build Settings' configure the 'Installation Directory' to '@executable_path/../Frameworks'
  3. Build library, and access the .framework from the archive or products directory

Including The Framework

  1. Drag the created .framework file into the Xcode Project, be sure to tick 'Copy Files to Directory'
  2. In the containing applications target, add a new 'Copy File Build Phase'
  3. Set the 'Destination' to 'Frameworks'
  4. Drag in the created .framework


回答3:

It was quite simple for me, i just added my framework to my embedded binaries under app targets



回答4:

The options above where not possible for me to include. I solved it by specifying the Runpath Search Path

This is on the 'Build Settings' tab. In the 'Linking' section. Change 'Runpath Search Paths' into $(inherited) @executable_path/Frameworks



回答5:

None of these issues solved this for me. The problem in the end was pretty easy. It looks like its a pretty major Xcode bug which I have logged the problem and fix under Apple bug: 29820370. If you are struggling (as it seems like there are several pages of problems similar to this ) then it would be great if you can raise a bug on bug reporter: https://bugreport.apple.com/ and reference the bug I raised to gain visibility. I want to make Xcode back into the pleasure that it was before - and this is something I am sure Xcode should have fixed itself.

Here is the fix: 1. Open Keychain - go to Apple Worldwide Developer Cert. 2. Double Click on it 3. Change the permission level from "always trust" to use System Defaults 4. Save and close it 5. Restart Xcode, Clean and build your project and it should be gone.

Screenshot below of the correct settings: Hope this helps!



回答6:

Deleting derived data saved it for me



回答7:

I ran into the same issue but the accepted solution did not work for me. Instead the solution was to modify the framework's install name.

The error in the original post is:

dyld: Library not loaded: /Library/Frameworks/TestMacFramework.framework/Versions/A/TestMacFramework
  Referenced from: /Users/samharman/Library/Developer/Xcode/DerivedData/TestMacContainer-dzabuelobzfknafuhmgooqhqrgzl/Build/Products/Debug/TestMacContainer.app/Contents/MacOS/TestMacContainer
  Reason: image not found

Note the first path after Library not loaded. The framework is being loaded from an absolute path. This path comes from the framework's install name (sometimes called rpath), which can be examined using:

otool -D MyFramework.framework/MyFramework

When a framework is embedded into an app this path should be relative and of this form: @rpath/MyFramework.framework/MyFramework. If your framework's install name is an absolute path it may not be loaded at runtime and an error similar to the one above will be produced.

The solution is to modify the install name:

install_name_tool -id "@rpath/MyFramework.framework/MyFramework" MyFramework.framework/MyFramework 

With this change I no longer get the error



回答8:

If you accidentally reset your keychain, this can occur due to missing Apple certificates in the keychain. I followed this to solve my problem.

I had the same issue and was able to fix by re-downloading the WWDR (Apple Worldwide Developer Relations Certification Authority). Download from here: http://developer.apple.com/certificationauthority/AppleWWDRCA.cer



回答9:

There should be a 'Run Script' into 'Build Phases' with this: '/usr/local/bin/carthage copy-frameworks'

On the 'Input Files' of that 'Run Script', you should add the path to your libraries. Like this:



回答10:

For Xcode 8, some stale products will be removed from derived data folder refer to this solution.

Apple: In macOS 10.12 and later, Xcode cleans up stale derived data, precompiled headers, and module caches. (23282174)

The Xcode build system supports stale file removal of some types of build artifacts that were produced in a previous build, but have since been removed from the project.

Base on the author's thought, I found this build log from my case.

Remove stale build products

/bin/rm -rf /Users/usename/Library/Developer/Xcode/DerivedData/myapp-esvvhwwwwngijeemhatmklwzoxnb/Build/Products/Debug-iphonesimulator/myapp.app/Frameworks/AliyunVodPlayerSDK.framework
/bin/rmdir /Users/usename/Library/Developer/Xcode/DerivedData/myapp-esvvhwwwwngijeemhatmklwzoxnb/Build/Products/Debug-iphonesimulator/myapp.app/Frameworks

After creating a new copy file phase and copy the target stale framework to Frameworks destination, the above removal log disappears after rebuilding.

Just clarify my situation and reason, hope it's helpful for someone.



回答11:

For me this was the solution, after many hours of searching!!

For some reason, well into the development of a Swift 2.3 custom Framework, Xcode 8 had removed the DYLIB_INSTALL_NAME_BASE setting from the project.pbxproj file. A little walk into the Build Settings / Dynamic Library Install Name Base setting back to @rpath fixed it.

(from https://forums.developer.apple.com/thread/4687)



回答12:

I found that this issue was related only to the code signing and certificates not the code itself. To verify this, create the basic single view app and try to run it without any changes to your device. If you see the same error type this shows your code is fine. Like me you will find that your certificates are invalid. Download all again and fix any expired ones. Then when you get the basic app to not report the error try your app again after exiting Xcode and perhaps restarting your mac for good measure. That finally put this nightmare to an end. Most likely this has nothing to do with your code especially if you get Build Successful message when you try to run it. FYI



回答13:

Got the issue when trying Xcode 9 beta and going back to Xcode 8. A simple Clean on the target resolved the issue.



回答14:

I had the same issue for a different reason. I've created a new configuration to Debug and Release (under PROJECT -> Info tab -> Configuration). And I had to change my pod frameworks shell script (Pods-"appName"-frameworks.sh , under Targets Support Files) to make it work.

[Xcode 9]



回答15:

The only thing that worked for me:

Target > Build Phases > [CP] Embed Pods Frameworks Uncheck "Show environment variables in build log" and "Run script only when installing"



回答16:

I tried many fixes, but what worked for me was to delete a missing target listed in the build tab of the build scheme. You can get to it by opening the edit window of the current scheme.

Edit: My UI testing target was not working as well, and the solution I found was to delete it and generate it again.



回答17:

open xcode -> general -> Embedded Binaries -> add QBImagepicker.framework and RSKImageCropper -> clean project

just add QBImagePicker.framework and RSKImageCropper.framework at embedded binaries worked for me



标签: