I was previously getting this error with my codesigned (sandboxed) application with an embeded JRE (following this tutorial):
Library not loaded: /usr/X11/lib/libfreetype.6.dylib
Referenced from: /Game.app/Contents/PlugIns/jdk1.7.0.jdk/Contents/Home/jre/lib/libfontmanager.dylib
What I did to fix this was to import these dylibs into the same directory as libfontmanager:
libfreetype.6.dylib
libpng16.16.dylib
libbz2.1.0.dylib
libSystem.B.dylib
libz.1.dylib
then running these commands on libfontmanager/libfreetype.6.dylib
install_name_tool -change /usr/X11/lib/libfreetype.6.dylib @rpath/libfreetype.6.dylib libfontmanager.dylib
install_name_tool -change /usr/local/lib/libfreetype.6.dylib @rpath/libfreetype.6.dylib libfreetype.6.dylib
install_name_tool -change /usr/lib/libz.1.dylib @rpath/libz.1.dylib libfreetype.6.dylib
install_name_tool -change /usr/lib/libbz2.1.0.dylib @rpath/libbz2.1.0.dylib libfreetype.6.dylib
install_name_tool -change /usr/local/lib/libpng16.16.dylib @rpath/libpng16.16.dylib libfreetype.6.dylib
install_name_tool -change /usr/lib/libSystem.B.dylib @rpath/libSystem.B.dylib libfreetype.6.dylib
I then codesign every dylib/jar + the app
codesign -v --deep --verbose=4 -f -s "3rd Party Mac Developer Application: Company" --verbose --entitlements Game.entitlements Game.app
find Game.app/Contents/ -type f \( -name "*.jar" -or -name "*.dylib" \) -exec codesign --verbose=4 --deep -f -s "3rd Party Mac Developer Application: Company" --entitlements Game.entitlements {} \;
The app runs flawlessly even after being codesigned!
The only problem is that after packaging and installing
productbuild --component Game.app /Applications -s "3rd Party Mac Developer Installer: Company" Game.pkg
sudo installer -store -pkg Game.pkg -target /
The app gives me this error upon opening it
lsd[346]: LaunchServices: Could not store lsd-identifiers file at /private/var/db/lsd/com.apple.lsdschemes.plist
kernel[0]: CODE SIGNING: cs_invalid_page(0x118113000): p=658[JavaAppLauncher] final status 0x3000200, denying page sending SIGKILL
kernel[0]: CODE SIGNING: process 658[JavaAppLauncher]: rejecting invalid page at address 0x118113000 from offset 0x15000 in file "/Applications/Game.app/Contents/PlugIns/jdk1.7.0.jdk/Contents/Home/jre/lib/libz.1.dylib" (cs_mtime:1476852998.0 == mtime:1476852998.0) (signed:1 validated:1 tainted:1 wpmapped:0 slid:0)
com.apple.xpc.launchd[1]: (com.company.gameOSX.80672[658]) Binary is improperly signed.
What's causing this?
EDIT: I found something that might answer my question. I ran these commands on the extracted app and it works completely fine.
sudo codesign -f -s - "/Applications/Game.app/Contents/PlugIns/jdk1.7.0.jdk/Contents/Home/jre/lib/libbz2.1.0.dylib"
sudo codesign -f -s - "/Applications/Game.app/Contents/PlugIns/jdk1.7.0.jdk/Contents/Home/jre/lib/libSystem.B.dylib"
sudo codesign -f -s - "/Applications/Game.app/Contents/PlugIns/jdk1.7.0.jdk/Contents/Home/jre/lib/libz.1.dylib"
What's causing these dylibs to not be codesigned properly after packaging and how do I fix this?
I figured it out. The dylib files that were causing the crash didn't work when codesigning it with my signing ID for some reason. Everything worked fine up until packaging and extracting which was odd.
I ended up removing the three dylib files that were causing the crash and my app worked even after extracting!