How do I properly embed third-party frameworks in my Cocoa application? - cocoa

I am writing a Cocoa application that makes use of the ParseKit framework (http://www.parsekit.com/). I've included the Framework in the proper folder, added a Copy Files build phase, and added it to the build phase. I can build and launch the application on my Mac.
However, when I try to run it on another Mac, it crashes. The Console shows the following error message:
dyld: Library not loaded: /Users/Jordan/Files/ParseKit/build/Debug/ParseKit.framework/Versions/A/ParseKit
It looks like when the app launches, it is looking for the framework on my local drive. However, the framework is in the Copy Files build phase, so it has been copied into that application's Contents/Frameworks folder. If if the application were looking in this folder, it would be able to load the framework just fine, but for some reason it's looking for it on my local drive on the original Mac (which obviously doesn't exist on the other Mac).
What am I doing wrong?

Use install_name_tool to change the framework’s install path to “#loader_path/../Frameworks/”.

Since it sounds like you're building it from source, set the install path in its Xcode project. You should submit a patch to the original developers once you get it working (partly to make it easier for you to keep up with future updates to the framework).

Related

macOS Application Bundle Frameworks Directory Codesign

I am packing my macOS application into an application bundle. I need to codesign it and pass notarisation. It is possible to put the frameworks in the "Resources" directory?
I have two frameworks. Normally, I used to put such frameworks into the "Frameworks" directory of the bundle. However, for (stupid) designing reason I need to have some more libraries in the same directory of my frameworks. Since such libraries will prevent code signing if placed in the directory "Frameworks", I want to move frameworks + extra libraries into the "Resources" directory.
Reading Apple documentation it seems that frameworks should - of course - belong to the "Frameworks" directory, however I could not find any reference to what should NOT be included into the "Resources" directory. Is this bad practice? Would my .app structure not pass gatekeeper?
Any suggestion would be very much appreciated
You've probably already tried putting a frameworks in Resources by now. As you said, even if it works today, this is not a good idea.
You might be able to work around whatever issue caused you to want to do this by using the install_name_tool to change one of the paths built into your frameworks. Adding symbolic links are another handy device for issues like this. This kind of stuff can be done automatically in a Run Script Build Phase or a Build Phase Post Action.

JavaFX Native Installer OSX Working Directory

On every other platform but Mac OSX, when I build and install a native package, the default working directory is "." to the JAR file. Even on OSX, if I delve inside the .app folder and manually run the JAR, the working directory is correct. However, if I run the application by simply clicking on the .app launcher, the working path ends up as "/Users/[username]
". Does anyone know how to configure the JavaFX native installer (perhaps info.plist?) to prevent this from occurring?
I think the launcher native executable sets this path. It is not plist configurable. The reasoning seemed to be in anticipation of OS X sandboxed applications and the limited file system access that they involve. So, basically there was no real good choice but they didn't want to encourage counting on access to the application bundle or it's parent directory.

How to use external Dll in Air Native Extension?

The structure of my ANE file looks like this:
<META-INF>
<ANE>
<Windows-x86>
ExtensionDll.dll
DllUsedByExtensionDll.dll
extension.xml
mimetype
catalog.xml
library.swf
If ExtensionDll.dll uses the functions in the other Dll, the extension won't load. DllMain is not called. It seems like DllUsedByExtensionDll.dll is not in the Dll search path when the air application uses the extension is running.
How should I make the application find the extra Dlls, if I don't want to put them into some common Dll path?
I've had the same problem and went at this for a few days. Turns out there's two ways to solve this.
Export Release Build, while making sure that the DllUsedByExtensionDll.dll is packaged in the same directory as your executable.
For debugging purposes, copy the DllUsedByExtensionDll.dll into your Adobe AIR SDK bin directory, where the Air Debug Launcher (adl) executable is located.
You do not need to package DllUsedByExtensionDll.dll in the ANE that you are building.
The problem is that ExtensionDll.dll cannot find the DllUsedByExtensionDll.dll when it is launched from the debugger, since the executable for the debugger is located in the AIR SDK. Once you export the release build however, the your app is the executable, so now it looks for the dll in its root directory.
If you want to debug this in order to find out more information on what could be wrong, I suggest that you run your app by command line using the adl command.
For me, running through Flash Builder's debug/run meant that I could not see the Windows error "the program can't start because dll is missing from your computer". And that led me on a wild goose chase for a long time.
If your dll is using other dlls then include the reference dll's in the project where you are going to use that ANE file.

Creating a Cocoa Framework

I've created a working Cocoa framework which I wish to redistribute. The problem is however, it won't run outside of Xcode. I've read something about #executable_path/../Frameworks, which I did not include, because I don't know where to put it :/
Therefore I run my app in Xcode using the DYLD_FRAMEWORK_PATH variable which works fine, but only in Xcode - if I try to run it on its own it crashes straight away and says IMAGE NOT FOUND.
I'm sure #executable_path/../Frameworks is what's missing, but I don't know where to put it.
Could anyone help me out please? :)
Thanks
Here is how I usually manage things:
In the framework's Xcode project, set the Installation Directory to #rpath
Add the framework to your application's Xcode project. Add a Copy Files build phase, select Frameworks in the Destination popup, and ensure your framework is added so it will be copied to your application's Frameworks directory when it is built.
Finally, in your project's settings, add #loader_path/../Frameworks to Runpath Search Paths.
Are you actually copying the framework into your applications bundle? Look for the folder called MacOS which is what contains the binary. There should be another folder at the same level called Frameworks and it should have the framework inside it.
If it's not there you need to create a copy files build phase for the application that copies the framework into the Frameworks folder.

Installing IB plugin

I have created IB kit plugin now i want to use that plugin in other Xcode project
how to do that? I have tried developers guide but not able to get that done ..please answer
First of all, I assume that you want your plug-in to be embedded within your application's bundle. If not, you can place the IBPlug-in framework in a standard location like /Library/Frameworks.
Creating the Plug-in
Once you have an IBPlugin project created in XCode using Apple's template, you need a little tweak:
Change the name of your framework target so it differs from the Plug-in's. For instance, you could call it MyIBPluginFramework.
In the Target Properties > Build : Modify the Installation Directory of MyIBPluginFramework to #loader_path/../Frameworks.
Also set its Dynamic Library Install Name to #executable_path/../Frameworks/$(CONTENTS_FOLDER_PATH)/$(PRODUCT_NAME).
Set the Installation Directory of MyIBPlugin to #loader_path/../Frameworks/Resources.
(when built, the plug-in is placed in the Resources directory of the framework).
At this point, it should work both in Interface Builder and in IBCocoaSimulator.
Embedding in an application
Drag the IBPluginFramework.framework folder to the Linked Frameworks group of the application's project. Edit your application target: append to Frameworks Search Paths the path #loader_path/../Frameworks/MyIBPluginFramework/Resources.
You're now able to link against the framework and the plug-in, but the framework must be copied to the Frameworks directory of your application when building. Add a Copy Files phase to your target, and drag the framework into.
I cannot garantee success (I managed to make mine work, but might have forgotten to relate a step here), but you're given the big lines.
I thought that usually you put plugins in to the application specific folder found in the Library folder either at the root or user level, e.g.
/Library/Interface Builder 3.0/
On my system I have another folder under that called "Library", and under that called "User Objects" which is empty.
So I would try putting it in each of these folders in turn, restarting XCode and Interface Builder each time (just to be sure)
/Library/Interface Builder 3.0/
/Library/Interface Builder 3.0/Library
/Library/Interface Builder 3.0/Library/User Objects
Hope that helps.

Resources