Xcode tests fail due to missing library in test bundle - xcode

Using Xcode 7.3, Cocoapods 0.39.0
At some point in the recent past, perhaps due to an upgrade of Xcode and/or Cocoapods, our tests stopped working with the following runtime issue:
2016-04-18 16:32:55.318 MyApp[15066:9003314] Failed to load test bundle
from file:///<huge filepath to .xctest wrapper>: Error Domain=NSCocoaErrorDomain
Code=3587 "dlopen_preflight(<same huge filepath to .xctest wrapper>): Library not
loaded: #rpath/Nocilla.framework/Nocilla
Reason: image not found" UserInfo={NSLocalizedFailureReason=The bundle is damaged
or missing necessary resources., NSLocalizedRecoverySuggestion=Try reinstalling the
bundle., NSFilePath=<huge filepath to .xctest wrapper>, NSDebugDescription=
dlopen_preflight(<huge filepath to .xctest wrapper>): Library not loaded:
#rpath/Nocilla.framework/Nocilla
I don't know anything like enough about Xcode and test bundle internals to debug this.
How do I restore my tests to working order? Thank you.
Edit: The only way I was able to unblock my work was to remove Nocilla. Fortunately, I discovered it wasn't actually used for anything. We just as well could have relied on it, however, so the question stands.

Related

ld: library not found for -lAnalytics error for expo bare workflow app on iOS

I'm getting the following error from xcode when I try to build a project I ejected from expo:
ld: library not found for -lAnalytics
I have the expo Segment package installed, and have gone through the regular ejection process, installing and configuring unimodules, and running npx install
Where should I start looking for this error? - Analytics (4.1.3) appears in my podfile.lock and I have an Analytics folder in the Library folder. I'm at a complete loss
The fix was exactly as #brentvatne said, I had opened the project via xcodeproj NOT xcworkspace. Xcode remembers your choice so on subsequent openings of xcode it had defaulted to xcodeproj.
Solution: open project with xcworkspace.

Getting "Library not loaded: #rpath/libswiftSwiftOnoneSupport.dylib" error

The problem occurred when I adding Nimble as a git submodule. I've fired an issue on Quick/Nimble, but the problem appears to be not likely a Nimble issue, it maybe rather an Xcode issue, thus I'm asking here.
I set up a simple project according to Nimble installation guid and it's on github now. Basically I created an xcworkspace and an xcodeproj (added to the workspace). Nimble is added as git submodule and subproject to the workspace. Then I added Nimble.framework to my test targets Build Phases and wrote some simple test code to see if Nimble was running.
And when I run the test, Xcode gave this error message:
2017-02-20 23:41:29.482 xctest[52165:616190] The bundle “MainProjTests” couldn’t be loaded because it is damaged or missing necessary resources. Try reinstalling the bundle.
2017-02-20 23:41:29.483 xctest[52165:616190] (dlopen_preflight(/Users/nandiin/Library/Developer/Xcode/DerivedData/NimbleIssue-fkhppktoktwpjodtarmzrjobszwv/Build/Products/Debug-iphonesimulator/MainProjTests.xctest/MainProjTests): Library not loaded: #rpath/libswiftSwiftOnoneSupport.dylib
Referenced from: /Users/nandiin/Library/Developer/Xcode/DerivedData/NimbleIssue-fkhppktoktwpjodtarmzrjobszwv/Build/Products/Debug-iphonesimulator/Nimble.framework/Nimble
Reason: image not found)
Program ended with exit code: 82
I've tried some solution I found for similar problems and they didn't work:
setting Embed Asset Packs In Product Bundle to YES (tried for both main target and test target)
setting Always Embed Swift Standard Libraries to YES (tried for both main target and test target)
The issue is the run path for the dynamic library:
libswiftSwiftOnoneSupport.dylib
If this is not included in the app bundle after building your app you'll want to add it by including it in the Copy Files Build Phase. Another possible problem could be that it's run path is not correctly set ( which you'll need to set if not already ), or fix the rpath with install_name_tool.
↳ Run-Path Dependent Libraries

Xcode can run my program, but I can't run it manually

I have a project with a dynamic library and an executable that links against it. I can successfully start it with Xcode, but when I try to run it from the command line, dyld complains about the library not being in the install path:
$ /Users/USER/Library/Developer/Xcode/DerivedData/PROJECT/Build/Products/Debug/EXECUTABLE
dyld: Library not loaded: /usr/local/lib/libMyLib.dylib
Referenced from: /Users/USER/Library/Developer/Xcode/DerivedData/PROJECT/Build/Products/Debug/EXECUTABLE
Reason: image not found
Trace/BPT trap: 5
The problem is quite clear: the library isn't in its advertised install path. However, I don't really want to deploy it there, and besides, Xcode still manages to start my program.
How can I run my program without installing the library in /usr/local/lib?
If you're relying on a dylib, then it needs to be installed in the appropriate location.
Using a framework might help, as you can package it in your application, using #executable_path...
But then, of course, you won't be able to share it across different applications.
So basically, you need to tell Xcode to install your dynamic library.
This can be done in your build settings, in the Deployment section.
Mainly, Deployment location, Installation directory, Skip install, etc...
Note that you can also do this for frameworks, installing them into /Library/Frameworks/

“ITunesSoftwareService” couldn’t be loaded because it is damaged or missing necessary resources."

I have seen others complain about this error. In my case I was able to trace it down to MacKeeper's Fast Cleanup feature.
I can reproduce the issue repeatedly with the following test:
1. With working version of Xcode 4.6, Clean, Build for OS Device & Archive: NO ERRORS
2. Kill Xcode
3. Start MacKeeper. Scan says there are several hundred "Junk" files. Press the "Fix this Problem" button. MacKeeper does its thing and reports all green.
4. Start up Xcode. Try to Clean, Build & Archive. Build fails with following error:
2013-02-06 16:45:17.568 Validation[39540:f07] Could not load framework at “file://localhost/Applications/Xcode.app/Contents/Applications/Application%20Loader.app/Contents/Frameworks/ITunesSoftwareService.framework/” (err = Error Domain=NSCocoaErrorDomain Code=3587 "The bundle “ITunesSoftwareService” couldn’t be loaded because it is damaged or missing necessary resources."
Here's the frustrating part. The only way to fix this is Re-install Xcode, Clean Build & Archive now works again. CLearly MacKeeper is removing something it should not!
I have reported this issue to MacKeeper but heard nothing back. Today I downloaded the latest update 2.4.1 and did my test with same results - Code broke again.
Can anyone else verify? I am ready to drop kick MacKeeper.

Deploying Qt Frameworks with Mac app and usage of otool

I have a problem deploying Qt frameworks with my Mac app, and I hope some will have a clue why I get this error, when I run the app on clean Mac, i.e. not a developer Mac.
OS: 10.7 .2 and using XCode
Error msg:
Library not loaded: #loader_path/../Frameworks/QtCore.framework/Versions/4.0/QtCore
Referenced from:/Users/someUser/Downloads/MainApp.app/Contents/Resources/Lib/Library.bundle/Contents/MacOS/../Frameworks/../Frameworks/QtXml.framework/Versions/4/QtXml
Clearly something is wrong since the QtXml is referenced from /../Frameworks/../Frameworks, which doesn’t exists.
This is the set up: I have a dylib that uses QtCore and QtXml (not by my choosing, but for now I need those two frameworks), the dylib is used in a NSBundle, which is loaded by the main app, the bundle is located in the resource folder. The dylib is moved by Copy Files Build Phase to the folder Contents/Frameworks and with otool the install_name is set to (as stated by http://doc.qt.digia.com/4.3/deployment-mac.html):
#loader_path/../Frameworks/QtCore.framework/Versions/4.0/QtCore
#loader_path/../Frameworks/QtXml.framework/Versions/4/QtXml
then the Qt frameworks are moved to Contents/Frameworks and the install_name of the is set to:
#executable_path/../Frameworks/QtCore.framework/Versions/4.0/QtCore
and for the QtXml
#executable_path/../Frameworks/QtXml.framework/Versions/4/QtXml
with reference to QtCore:
#executable_path/../Frameworks/QtCore.framework/Versions/4.0/QtCore
Now when I run the app on the developer mac it clearly works since Qt is installed, but when moved to a clean mac I get the error msg, readable in the Console app.
I’ve tried to change the executable_path to loader_path, but this didn’t work.
I have no idea what I’m doing wrong or why it won't for, and have not been able to find anything on Google, of course I could be looking at the wrong places. Any ideas how to fix this problem?
This is the entire error message:
MainApp: Error Domain=NSCocoaErrorDomain Code=3587 "The bundle
“Library” couldn’t be loaded because it is damaged or missing
necessary resources."
(dlopen_preflight(/Users/someUser/Downloads/MainApp.app/Contents/Resources/Lib/Library.bundle/
Contents/MacOS/Library): Library not loaded:
#loader_path/../Frameworks/QtCore.framework/Versions/4.0/QtCore
Referenced from: /Users/ someUser /Downloads/
MainApp.app/Contents/Resources/Lib/Library.bundle/Contents/MacOS/../Frameworks/../Frameworks/QtXml.framework/Versions/4/QtXml
Reason: image not found) UserInfo=0x107c5d5d0
{NSLocalizedFailureReason=The bundle is damaged or missing necessary
resources., NSLocalizedRecoverySuggestion=Try reinstalling the
bundle.,
NSFilePath=/Users/someUser/Downloads/MainApp.app/Contents/Resources/Lib/Library.bundle/Contents/MacOS/Library,
NSDebugDescription=dlopen_preflight(/Users/someUser
/Downloads/MainApp.app/Contents/Resources/Lib/Library.bundle/Contents/MacOS/Library):
Library not loaded:
#loader_path/../Frameworks/QtCore.framework/Versions/4.0/QtCore
Referenced from:
/Users/someUser/Downloads/MainApp.app/Contents/Resources/Lib/Library.bundle/Contents/MacOS/../Frameworks/../Frameworks/QtXml.framework/Versions/4/QtXml
Reason: image not found,
NSBundlePath=/Users/someUser/Downloads/MainApp.app/Contents/Resources/Lib/Library.bundle,
NSLocalizedDescription=The bundle “Library” couldn’t be loaded because
it is damaged or missing necessary resources.}
On the development mac everything works because the Qt libraries are installed. On any mac you ship the app to, though, this likely won't be the case. The Qt suite comes with a tool called macdeployqt to fix this. So in a terminal, after you've compiled your application, do something like:
# cd my-cool-app-Desktop
# macdeployqt my-cool-app.app
Note that it can also be used to create a .dmg file for shipping everything together:
# cd my-cool-app-Desktop
# macdeployqt my-cool-app.app -dmg
Once you've done that, the .app directory or .dmg file can be given to someone else without Qt installed to use and run as they normally would.
The one caveat is that the next time you try to run it on your developer machine, it may complain about multiple shared libraries installed. So once you've copied it else where in order to distribute it, remove the entire .app directory and let qtcreator (or whatever) rebuild it.
UPDATE
As stated compiling QT to static libs is the way to go. With the release of Mavericks (10.9) we need to codesign frameworks as well (http://furbo.org/2013/10/17/code-signing-and-mavericks/), and with QT4.8.5 there are some issues (https://bugreports.qt-project.org/browse/QTBUG-32896). Even with suggested fixes I still had some issues when running the app on a clean machine. Therefore, I ended up with compiling Qt5.2 to staticlibs, link them in the app, and codesign them.
OLD
Problem sovled, I moved the Qt-frameworks into the app bundle in Contents/Frameworks and with otool set the path to #executable_path/../Frameworks, i.e. moved it out of my library bundle. Yes the solution is simple, but I'm still not sure why the library executable couldn't find the frameworks when using #loader_path.
The best solution would probably be to use a static library and not wrap it in a bundle...you learn everyday ;)

Resources