I am trying to create a wrapper (bundle) for an OS X framework. In Unity, I’m getting the following error:

 Couldn't open Assets/Affdex/Plugins/affdex-native.bundle/Contents/MacOS/affdex-native, error: dlopen(Assets/Affdex/Plugins/affdex-native.bundle/Contents/MacOS/affdex-native, 2): Library not loaded: affdex-native.framework/Versions/2.1.0./affdex-native
  Referenced from: /Users/foresthandford/git/unity/UnityPlugin/Assets/Affdex/Plugins/affdex-native.bundle/Contents/MacOS/affdex-native
  Reason: image not found

From my searches on this forum, “image not found” often means there is either no binary or an inappropriate binary. The bundle has a universal binary:

ForestsMacbook:Plugins foresthandford$ file affdex-native.bundle/Contents/MacOS/affdex-native
affdex-native.bundle/Contents/MacOS/affdex-native: Mach-O universal binary with 2 architectures
affdex-native.bundle/Contents/MacOS/affdex-native (for architecture x86_64):	Mach-O 64-bit bundle x86_64
affdex-native.bundle/Contents/MacOS/affdex-native (for architecture i386):	Mach-O bundle i386

The versioning from the framework seems, however, to be incorrect:

ForestsMacbook:Plugins foresthandford$ otool -L affdex-native.bundle/Contents/MacOS/affdex-native
affdex-native.bundle/Contents/MacOS/affdex-native:
	affdex-native.framework/Versions/2.1.0./affdex-native (compatibility version 0.0.0, current version 0.0.0)

Currently the framework appears as part of the binary within the bundle. I’ve heard a suggestion that the framework may need to exist as files separate from the binary (ie: not just compiled into the binary).

  1. Is framework inclusion really the issue?
  2. If it is, how do I fix it?
  3. Does someone have an example XCode project I could look at (I found several OS X plugins in GitHub but none included the .xcodeproj file)?

The closest related question I could find was Building OSX Bundles for Unity Extensions with External Frameworks - Questions & Answers - Unity Discussions , but it doesn’t show how the framework was included. This is my first foray into XCode and I might be missing something obvious.

This has been resolved. I’m not sure ALL the steps I took were needed.

  • I replaced the framework I was using with a dynamic library. The theory was that because I was using dlopen I should be using a dynamic library.
  • I put the dynamic library inside the bundle at the same location as the binary (affdex-native.bundle/Contents/MacOS)
  • I used ‘install_name_tool -id @loader_path/libaffdex-native.dylib libaffdex-native.dylib’ to change the path to the dynamic library. Note, this was the most obscure change I made and it took all the Google-fu I had to find it.

Here is a blog post with more details.