Library not Loading/Image not Found - Swift 4.0 - swift4

So I am very new to Swift and XCode. I am trying to use an external library called JJFloatingActionButton the projects build fine but when I try run it on an emulator I get:
dyld: Library not loaded: #rpath/JJFloatingActionButton.framework/JJFloatingActionButton
Referenced from: /Users/mkangwa/Library/Developer/CoreSimulator/Devices/
3E58C8A1-3F02-4CA0-8EF3-A79311A202A2/data/Containers/Bundle/Application/D8BBF9A8-5BC7-4619-
B08C-2E6F7C6BCB85/DriversHub-iOS.app/DriversHub-iOS
Reason: image not found
Now of course I know you can't come ask a question like this on StackOverflow without researching and trying to find a solution yourself, so thats what I've been doing for the past few hours I have been looking at what was causing this, I started thinking that maybe it was the library it's self so this one is the third or fourth I've tried till I came across a few posts on SO that were about this issue.
Most people fixed this by just putting the Framework into the Embedded Binaries in the targets General Settings. And I tried this but I now receive a log:
I also get a Dependancy Analysis Warning:
I don't know much about these types or warning and errors but it's saying that it can't find the file which is pretty self explanatory but when I am adding the file to Embedded Binaries it shows the framework file there

What I often do when I have problems with cocoapods is remove cocoapods from the project and reinstall it.
You could use pod deintegrate (https://github.com/CocoaPods/cocoapods-deintegrate) to remove it and then a pod install to reinstall.

So it took a day and a half to work this out but I have finally got it and I can carry on with my project.
Problem:
The problem in my particular case (because other methods seemed to have worked for people trying to achieve the same thing) that the reason my project wouldn't build and was throwing Build Time errors was because after adding the Framework to Embedded Binaries it was also adding it to Embed Frameworks in my targets Build Phases. This then, I believe, caused the compiler to try and build it twice hence the Multiple Build Commands error
Solution:
So the errors I kept getting where saying No such file or directory above it was saying Multiple build commands for output file and what I did to fix this I went to Build Phases in my target settings and deleted the framework from Embedded Frameworks but made sure it was still under [CP] Embed Pods Frameworks.

in my case I was have to make framework "embed & sign" in stead of "don't embed"

Related

How to link custom framework within UITest target in Xcode - another "Library not loaded - #rpath"-issue

My project uses Xcode 11.3.1 and is structured as followed:
MyProject
- MyProject.xcworkscapce
- MyFramework
- MyApp
-MyApp (main-target)
-MyAppUITests (uiTest-target)
MyApp imports MyFramework and can be built und run just fine. For this to work I added MyFramework to main-target into main-targets General/Frameworks and Libraries.
In my UITest target I need to access some classes (Accessibility-Identifier-Definitions) from MyFramework, so I need to import these somehow.
Both targets are building and the main-target works without any issues. I am also able to run ui-tests on a simulator. Unfortunately I am forced to run my tests on real devices, and here I get this runtime error:
The bundle “MyAppUITests” couldn’t be loaded because it is damaged or missing necessary resources. Try reinstalling the bundle.
(dlopen_preflight(/var/containers/Bundle/Application/E581B3BA-A9A2-4AA3-A1BA-91C57DCD3846/MyAppUITests-Runner.app/PlugIns/MyAppUITests.xctest/FHCommunityUITests): Library not loaded: #rpath/MyFramework.framework/MyFramework
Referenced from: /var/containers/Bundle/Application/E581B3BA-A9A2-4AA3-A1BA-91C57DCD3846/MyAppUITests-Runner.app/PlugIns/MyAppUITests.xctest/MyAppUITests
Reason: image not found)
I am fairly new to this framework-thing (and also to ui-tests) and it's been two days I am dealing with this issue now. Most posts about similar issues are related to misspecified Podfiles, but in my barebone sample project which I setup to not destroy my real project I am not using any Pods. I tried probably all of the suggested solutions (and almost all combinations :() and none of them seem to work.
It took me a while to figure out that in my uiTest-target build phases I can actually add a New Run Script Phase and I assume I need to somehow link MyFramework here.
Is this correct? Can someone help me defining the run script?
And yes, I tried to clean my app (and I also deleted derived data).
Help is highly appreciated. Thank you!
Ok, finally I figured it out. The solution is fairly simple and I haven't seen anyone suggesting this. Here we go:
To use your custom framework in your app target simply add it under Frameworks, Libraries, and Embedded Content:
Now you can access MyFramework from the main target.
I could also run my ui-tests from the simulator, but still got the error described above when executing my ui-tests from my real devices.
To get rid of the The bundle “xxxUITests” couldn’t be loaded because it is damaged or missing necessary resources. Try reinstalling the bundle.-Error I had to go to my uiTest-target and link the framework in my build phases.
As Destination choose Frameworks and select the Framework you want to use in your uiTest-target.
Now you should be able to run your ui-Test from your device.

"Copy swift standard libraries" build step does not include SwiftOnoneSupport.dylib

I have been experiencing a troubling problem lately that has to do with the running of tests on a project which has a cocoapods dependency to a framework which crashed at runtime with error:
Library not loaded: #rpath/libswiftSwiftOnoneSupport.dylib
Referenced from: MyCocoapodsDependency
There are other stackoverflow topics out there about that particular problem but none of them address root cause (for example here), which is that during the "Copy swift standard libraries" step of the test build, the missing library is not copied over.
It looks like this (this is the build log when I build the tests):
When it should look like this (this is the build log for a test app that uses the exact same dependencies):
OnOneSupport seems to have to do with with a project setting that has to do with "Whole module optimization".
But even if I change to "not onOne" it doesn't make a difference. The dylib is referred to in https://github.com/apple/swift/blob/master/cmake/modules/AddSwift.cmake
I cannot for the life of me figure out why it's omitted from the standard libraries build step for one target and not for another, but its obvious that my tests needs it. Anybody know how I can force the compiler to include SwiftOnoneSupport?
Workaround
Add a build phase to the test target (in the project file) that copies libswiftSwiftOnoneSupport.dylib to Frameworks. The dylib can be found at:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/bitcode_strip /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/libswiftSwiftOnoneSupport.dylib
I also had this same issue with two of my frameworks. The strangest thing was that everything was working fine with one of them but not with the other.
While I wasn't able to figure out why this happens (since it seems to be an Xcode bug), I was able to find a pretty neat workaround.
Turns out that using print() anywhere in your code will somehow force libswiftSwiftOnoneSupport.dylib to be loaded. So, by adding something like this the problem should go away:
private func dummy() {
print("Hello world!")
}
I'm using Xcode 10.1, Swift 4.2 and the pod that was giving me this issue was Nimble.
Hope this helps!

Cocoapods: dyld library not loaded

So since a few days I have this issue: I create an empty command line project and set up Cocoapods, but then I always get this runtime error:
dyld: Library not loaded: #rpath/Alamofire.framework/Versions/A/Alamofire
Referenced from: /Users/...
Reason: image not found
Program ended with exit code: 9
This happens regardless of the pod I want to use and also in already existing projects. Windowed Cocoa applications and iOS apps are not affected. I tried setting the pods.framework to Optional as suggested elsewhere, but this doesn't help. I tried it with the newest Cocoapods beta and the stable release and reinstalled Xcode, but without success. I noticed under Build Phases there is no 'Embed Cocoapods framework' as usual, so I tried adding that manually; didn't work either.
I've run out of ideas, so does anybody have any idea what might cause this? Otherwise I'll file a bug report. Thanks.
As it turns out, this behaviour is expected, as there is no easy way (for CP) to link libraries to a command line tool.

Getting dyld_fatal_error after updating to Xcode 6 beta 4 using swift

I just recently downloaded Xcode 6 beta 4, and my swift project compiles with no errors but before it gets to my code I get a dyld_fatal_error just above start in the call stack.
and a breakpoint in some assembly code with a nop instruction
The console error I get is
dyld: lazy symbol binding failed: Symbol not found: __TFSsa6C_ARGVGVSs13UnsafePointerGS_VSs4Int8__
Referenced from: /Users/username/Library/Developer/Xcode/DerivedData/Sudoku-dhrdonaeqzsgcvewndimxbbsltnc/Build/Products/Debug/Sudoku.app/Contents/MacOS/Sudoku
Expected in: /Users/username/Library/Developer/Xcode/DerivedData/Sudoku-dhrdonaeqzsgcvewndimxbbsltnc/Build/Products/Debug/Sudoku.app/Contents/MacOS/../Frameworks/libswift_stdlib_core.dylib
dyld: Symbol not found: __TFSsa6C_ARGVGVSs13UnsafePointerGS_VSs4Int8__
Referenced from: /Users/username/Library/Developer/Xcode/DerivedData/Sudoku-dhrdonaeqzsgcvewndimxbbsltnc/Build/Products/Debug/Sudoku.app/Contents/MacOS/Sudoku
Expected in: /Users/username/Library/Developer/Xcode/DerivedData/Sudoku-dhrdonaeqzsgcvewndimxbbsltnc/Build/Products/Debug/Sudoku.app/Contents/MacOS/../Frameworks/libswift_stdlib_core.dylib
Just so you know the project still compiles, and runs fine with Xcode 6 beta 3.
Most extremely weird problems like this can be solved with a Clean & Build (or perhaps relaunch Xcode). You might also consider deleting the relevant folders from ~/Library/Developer/Xcode/DerivedData.
For sure this error is very unhelpful:
dyld`dyld_fatal_error:
-> 0x1200ad088 <+0>: brk #0x3
This of course occurs only on device, not the simulator. Another good reason to always test on a device.
Anyway, having had the same issue, a clean didn't work for me. Deleting DerivedData didn't help either. Also tried synchronising the Deployment Target versions. That didn't seem make any difference but I did it anyway.
Solution was to add any dynamic frameworks to Embedded Binaries setting under Target -> General:
Now I know that has been mentioned in other answers. However, if I can supplement by saying that any dependent dynamic frameworks must also be included.
So for example if you have a dynamic framework A that depends upon dynamic framework B, then it's necessary to have A and B added to Embedded Binaries.
Note that if the dynamic framework A depends upon any static library or framework, you will almost certainly be forced to create A as an umbrella framework that includes the dependant binaries.
Other considerations that may or may not be important. However did personally for me result in success were;
paths of each dynamic library in the Inspector were set to "Relative
to Group". In the screen grab above the path of the embedded binary
appears correct terminating with "build/Debug-iphoneos".
dynamic frameworks are in embedded binaries section. Static libs and
static libs wrapped up as frameworks are in Linked Frameworks
and Libraries. Nothing appears in both sections.
In setting this up XCode behaved strangely. The following proved successful:
Add the dynamic framework to the embedded binaries.
Find the new framework in XCode groups on the left and update the path to be
"Relative to Group" as described previously.
Delete the dynamic framework from embedded binaries.
Add the dynamic framework to the embedded binaries again. The path should now appear correctly.
Delete all references to the dynamic framework from the Linked Frameworks
and Libraries section.
I have just had this problem trying to link a custom iOS framework to my project, so for anyone out there who has this problem, it's to do with the copy files build phase.
I think that this error results when a file cannot be found. So create a copy files build phase in the appropriate target in your project. Then add the file (in my case the custom framework) to this phase (if it's a framework make sure to select the 'Frameworks' destination).
Cleaning, restarting, deleting etc didn't work for me.
I have a project containing another project. When I ran the project on iOS 7 and the contained project was accessed in code, the app stopped at the line below:
After many days, I saw that the deployment target for the container project was 7.0 (as can be seen below).
The contained project on the other hand, had a deployment target of 8.1 (as can be seen below).
Changing the deployment target of the contained project to 7.0 solved my problem!
The project was working fine on iOS 8 devices.
I had this issue recently and the problem for me was that I had added a library from the same project which wasn't listed in 'Embedded Binaries' from the 'General' section.
NOTE: If you add it in Embedded Binaries it will also add to the Linked Libraries section, possibly adding the same one twice.
Clean and build won't work. You'll need to delete he cache in ~/Library/Caches/com.apple.dt.Xcode* directories. Delete these and rebuild.
Do this every time you upgrade the beta.
I also faced the same issue and tried all the solution given above without any luck.
then what I have done to resolve that I really don’t have much I idea about. So there is Certificated called “apple worldwide developer relations certificate authority” in System group in keychain Access and due to some profile and certificate issue I randomly mark this certificate “Always trusted” from “Use System Defaults”. So this is causing this “dyld_fatal_error” crash to me. when I revert it back to “Use System Defaults” crash got resolved.
So guys if you are tried all the possible option to resolve this crash and didn’t succeed yet, try this also. It helped me, may help you as well.
Found this about this certificate.
This problem still occurs in Xcode 7, and it can happen for a variety of reasons (it seems). In my case, the iOS app with an included framework:
ran on the simulator fine
gave the error you described on the device
The answer was to NOT use linked libraries but rather Embedded Binaries under General.
Also see here: https://stackoverflow.com/a/34052368/8047
Adding the non-system Framework to "Embedded Binaries" inside the general tab of the main project worked for me.
As stated by bitwit, this will also add your framework to "Linked Frameworks and Libraries", so watch out for those duplicates.
Tested with Xcode 7.3.
Xcode 8.
Clean and build didn't work. I deleted the cache, deleted Derived data. After that, my pods configuration was broken, so i needed to install pods again. Pods Target configuration was set to a very old Valid architectures. setting to armv7 and armv7s, was ok to compile and no problems
You'll get this if your scheme has "Guard Edges" enabled in diagnostics when running on an actual device. "Guard Edges" only works in the simulator.
I was using cocoapods and had this problem as well when I updated to deploy target iOS 8 and added use_frameworks! to my Podfile. I was able to fix it by adding the following line to my Podfile:
link_with 'TargetName1', 'TargetName2', etc.
Might work with ProjectName as well

Linker command failed with exit code 1 error in Xcode project

I was working on my project and suddenly after editing the code and compiling gave this error:
ld: warning: directory not found for option '-
L/Users/mani/Documents/Classes/Twitter+OAuth/Libraries & Headers' ld:
duplicate symbol _OBJC_CLASS_$_playSiew in
/Users/mani/Library/Developer/Xcode/DerivedData/learn-aktrtiwswclovoatyweyquoxmypa/Build/Intermediates/learn.build/Debug-iphonesimulator/learn.build/Objects-normal/i386/playSiew.o
and
/Users/mani/Library/Developer/Xcode/DerivedData/learn-aktrtiwswclovoatyweyquoxmypa/Build/Intermediates/learn.build/Debug-iphonesimulator/learn.build/Objects-normal/i386/Thumb.o
for architecture i386 clang: error: linker command failed with exit
code 1 (use -v to see invocation)
I never touched the project settings, just edited the code.
What's more strange is that I took out last revised code from svn but still I got the the same error.
You may be accidentally #import'ing a .m file instead of a .h. Use Cmd+Shift+F and search for ".m" (without quotes). It will most likely lie in one of the classes mentioned in the warning. If not, clean and run again.
I was also having same issue and I did following and issue is gone.
Go to Product -> Clean and re-run the project.
I hope it might be useful for some other developers.
After running into this problem a few minutes ago (yes, I know it's been 7 months since the original thread) I found that the root of my issue was due to me dragging & dropping files into my project within XCode instead of right-clicking and choosing Add Files to Project.
Check playSiew.m is in Compile Sources section. isn't it?
You can find Compile Sources section follow this step
Select YourProjectName
Select TARGETS
Select Build Phases
If don't have playSiew.m in this section . You must to add it to this section.
As I said the problem wasn't the code but some settings. So what I did was copying the code from my friends' Mac (it was working fine), and installed a fresh copy of the project to my Mac. It worked.
I was importing a library in a test case which I had specified in my pod file for the main target but not for the test target.
I also got this error because I had accidentally included two versions of the same source file. Deleted the wrong one and the problem went away...
If you're working in Unity and export to iOS and you are using a plugin, go to Xcode Build Settings and set ENABLE BITCODE = NO. I'm guessing this might apply to other situations as well
Faced similar issue, while running the code on a simulator, tried all the above mentioned options, still got the same error. Tried connecting the iOS device and build the code, it worked for us. This can be a quick workaround.
the same error i faced. so, i just removed reference of that classes which are generating the errors and than again gave reference and the error was gone...
as D80Buckeye says there should be problem of dragging and dropping files instead of Clicking on "Add Files"
In case this comes in useful for anyone else--I just had this same error, and turns out the cause was initializing a variable in my header file rather than in the main file.
I just encountered the same error. If you are using embedded Libraries, make sure your Deployment Target is set to iOS 8.0 or higher.
you only need to add the following framework: quartzcore.framework
The only way we can get past this bug on our project is to do a Clean and then build for iPad Retina. After that it will build successfully for any device. Weird.
In my case i have add reference of FacebookLoginSDK framework but forget to give search path in build setting. After removing its reference everything was fine.
So conclusion is if you are adding any external framework be careful.
If this happens to you with CoreData generated classes, combine the +CoreDataProperties and +CoreDataClass into the +CoreDataProperties class and delete the +CoreDataClass. Make sure to search Derived Data for leftovers of the +CoreDataClass. Even after deleting the Derived Data and cleaning I sometimes had Xcode just generate the +CoreDataClass again and again. Deleting it manually in Finder and then re-bulding helped me solve this.
try this, go to Target -> Build Settings,then search these three as following,
GCC_NO_COMMON_BLOCKS,
CLANG_WARN_INFINITE_RECURSION,
CLANG_WARN_SUSPICIOUS_MOVE,
set NO to each value then clean and build.
I tried several of the answers listed but none worked for me.
I got the error after updating XCode (while it was still open which may have contributed to the problem)
First, I deleted my Derived Data folder:
XCode => Preferences => Locations => Double Click on arrow next to path indicating where the Derived Data folder is.
Then "Move to Trash"
I don't think that's what the problem was, but it's amazing how many times this has been an issue for me working on different problems.
Second, I 'Quit' the simulator.
Third, I 'Quit' XCode.
Fourth, I opened up my project in XCode again and then did a Clean and Build (found in the Product menu)
Fifth, I ran my project and it worked fine
Cleaning the project not works for me.
Restart the Xcode works for me...
For me it was different. I had the same error when I removed a Pod and solved it by removing this pod from the Other Linker Flags in the Build Settings
then clean your project [Product > Clean] and rebuild
Go to general and linked frameworks and libraries in xcode and remove all the files there.