Segmentation fault on fresh cocoapod install - swift

I have a new Swift project I started on and the first thing I did was create my podfile and bring in two cocoapods.
target 'Life Stream' do
pod 'SSKeychain'
pod 'LiveSDK'
end
target 'Life StreamTests' do
pod 'SSKeychain'
pod 'LiveSDK'
end
I then ran pod setup to ensure my cocoapods were installed, then ran pod install to install my pods. The new workspace project was created and I opened Xcode in it. Everything builds.
I then added my bridge header, and started using the SSKeychain pod. Things continued to build.
Bridge:
#ifndef Lifestream_Bridging_Header_h
#define Lifestream_Bridging_Header_h
#import "AFNetworking/AFNetworking.h"
#import "SSKeyChain.h"
#import "LiveConnectClient.h"
#endif /* Lifestream_Bridging_Header_h */
class UserService {
init() {
SSKeychain.setPassword("test", forService: "service", account: "blah")
}
}
I then try to use the LiveSDK
class HttpOperation : NSOperation, LiveAuthDelegate {
let baseUl = NSURL(string: "https://api.onedrive.com/v1.0")
override func main() {
let client = LiveConnectClient(clientId: "000000004C1549C8", delegate: self)
}
func authCompleted(status: LiveConnectSessionStatus, session: LiveConnectSession!, userState: AnyObject!) {
}
}
The project built a couple of times, but now it no longer builds. I've not changed a line of code (CMD+tabbed to Safari for research). It doesn't matter if I clean the project, rebuild, or delete all of my pods and reinstall them, I can't get the project to build.
The compiler error I receive
Command failed due to signal: Segmentation fault: 11
I've seen people say this can be caused by the compiler not being able to find linked stuff. I then looked and noticed that my /frameworks folder contains all of the .a files in red (linked files?)
I assume that's because the files are missing, but why would that be? If I installed the pods via cocoapods and they were building fine, why now would those files go missing and the build stop (if that is the cause)?
I've been trouble shooting this for the last few hours and have not been able to figure it out. Any help would be appreciated.
My full compiler error log dump can be found on github
Edit
There are additional build errors associated with the unit test project, but I assume those are due to the project the unit tests depend on not building.
Use of undeclared type 'LiveAuthDelegate'
Use of undeclared type 'LiveConnectSessionStatus'
Use of undeclared type 'LiveConnectSession'
Use of unresolved identifier 'LiveConnectClient'
These errors point to the NSOperation subclass I show above. I'm not sure if that helps or not.

Related

Firebase Analytics throws errors on building in xcode

I am trying to implement analytics by firebase, I have imported the FirebaseAnalytics pod in my class, but when I try to use any of it's methods, there are errors on xcode build, please help me resolve this issue, I tried most of the solutions adding the $(inherited), adding -Objc, but none of them seem to work, please point me to right solution
Implementation
import FirebaseAnalytics
class PerformanceHandler {
func recordCustomEvent(name: String, attributes: [String: Any]) {
Analytics.logEvent(name, parameters: attributes)
}
}
Error
I am on Xcode 14 and the latest version of cocoapods 1.11.3.
Podfile (Sorry wouldn't be able to add the entire podfile, here is a gist of it)
pod 'Firebase'
pod 'Firebase/RemoteConfig'
pod 'FirebasePerformance'
The PerformanceHandler class mentioned above is part of a custom pod, the code is split into respective Pods following a modular architecture.

Swift PaperOnboarding Module Import Error

I am sorry for such simple question, but I've searched everywhere and read through the paper-onboarding documentation but still can't find a solution to this problem.
I am building a simple iOS app project using the paper-onboarding library, by following this YT tutorial. I keep receiving the error: No such module 'PaperOnboarding'
import UIKit
import PaperOnboarding // <<<ERROR HERE>>>
class OnboardingView: PaperOnboarding {
/*
// Only override draw() if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
override func draw(_ rect: CGRect) {
// Drawing code
}
*/
}
I'm not sure how to solve this, could someone shed some light on this?
Xcode: Version 9.3
Cocoapod: Version 1.4.0
Paper-onboarding: Version 4.0.2
This error has nothing to do with the library. It's definitely an error on your part or on the configuration of your project.
How are you adding the library to your project?
If you're adding using CocaPods:
Make sure you do pod install or pod update
After that always open the .xcworkspace file in your project and not the .xcodeproj
If you are opening the correct file:
Check the POD project and the target for the pod you added and in the build settings, make sure Swift Version matches your project version.
Clean your project and run
Close and re-open XCode
but it could be several other things. But make sure all the configuration is correct.
Some Pods require you to use the use frameworks! statement in the Podfile.

Swift 3 Unit Testing - Linker fails when using import #testable

I'm currently trying to write unit tests (NOT UI Tests) for my (macOS) Xcode project. I have created a new Unit Test target which creates a blank unit test file for me.
This complies and links fine, but there are no tests.
As soon as I add the line #testable import Pilot, where Pilot is the name of my App Target, and I try to compile and run, it fails with this message:
Linker command failed with exit code 1 (use -v to see invocation)
I've tried everything I can find, but nothing seems to be working. The other posts I have read on here deal with this problem in UI Tests, but that is because you cannot use #testable in UI Tests. You are supposed to be able to use it in Unit Tests, but I can't figure out why this is not working.
Does anyone have any insight?
If it helps, my project is located at: https://github.com/RohanNagar/pilot-osx
Here is the full PilotTests.swift file:
import XCTest
#testable import Pilot
class PilotTests: XCTestCase {
override func setUp() {
super.setUp()
// Put setup code here. This method is called before the invocation of each test method in the class.
}
override func tearDown() {
// Put teardown code here. This method is called after the invocation of each test method in the class.
super.tearDown()
}
func testExample() {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct results.
}
func testPerformanceExample() {
// This is an example of a performance test case.
self.measure {
// Put the code you want to measure the time of here.
}
}
}
If your CocoaPods frameworks not included in the Test targets. It will throw this error.
I made sure running a pod install, but still it failed.
So 'pod deintegrate Yourproject.xcodeproj' and reinstall (pod install), clears the issue.
The import fails because the project fails to link together. I downloaded it and I get the following error trying to run it:
Showing Recent Issues
ld: framework not found Realm for architecture x86_64
Try to clean your build folder, or download the project to a new folder, and fix this issue... after that you'll be able to compile and #testable import Pilot.
Set Host Application to your Project Target.
Also, check the Allow testing Host Application APIs is turned on.
Select your test target
Select Build Phases
In the Framework Search Paths, add this
"${PODS_CONFIGURATION_BUILD_DIR}/" with recursive option

Early grey environment setup

I'm trying to get Earlgrey setup on my computer by following the steps for Cocoapod installation as described here
After performing all the steps I keep on getting compilation error during build
EarlGrey.swift:17:27: Use of undeclared type 'EarlGreyImpl'
There are 13 such compilation errors all related to unresolved identifier.
I re-tried the steps multiple times with same results. My folder structure matches with what is shown in the instructions.
Any suggestions where should i look further to get this resolved.
For reference i'm using this swift project as base for writing test cases.
So the issue was related to BridgingHeader.h file setting in
test target -> build Setting -> Swift compiler -Code generation -> Objective-C bridging Header
I copied the file from demo project, but did not specify it in the above setting. Once specified there, the compilation errors was gone.
Try importing EarlGrey using #import <EarlGrey/EarlGrey.h> instead of #import EarlGrey;

MacOS Swift Framework testing fail

I have a framework written in obj-c and swift.
Now i try to run a related unit test target, but I get this error:
2014-07-10 07:45:54.064 xctest[4908:303] The test bundle at /Users/steve/Temporary/Build/Products/Debug/SOGraphDB-Mac Tests.xctest could not be loaded because an unanticipated error occurred: Error Domain=NSCocoaErrorDomain Code=3587 "The bundle “SOGraphDB-Mac Tests” couldn’t be loaded because it is damaged or missing necessary resources." (dlopen_preflight(/Users/steve/Temporary/Build/Products/Debug/SOGraphDB-Mac Tests.xctest/Contents/MacOS/SOGraphDB-Mac Tests): Library not loaded: #rpath/libswiftAppKit.dylib
Referenced from: /Users/steve/Temporary/Build/Products/Debug/SOGraphDB.framework/Versions/A/SOGraphDB
Reason: image not found) UserInfo=0x10011c640 {NSLocalizedFailureReason=The bundle is damaged or missing necessary resources., NSLocalizedRecoverySuggestion=Try reinstalling the bundle., NSFilePath=/Users/steve/Temporary/Build/Products/Debug/SOGraphDB-Mac Tests.xctest/Contents/MacOS/SOGraphDB-Mac Tests, NSDebugDescription=dlopen_preflight(/Users/steve/Temporary/Build/Products/Debug/SOGraphDB-Mac Tests.xctest/Contents/MacOS/SOGraphDB-Mac Tests): Library not loaded: #rpath/libswiftAppKit.dylib
Referenced from: /Users/steve/Temporary/Build/Products/Debug/SOGraphDB.framework/Versions/A/SOGraphDB
Reason: image not found, NSBundlePath=/Users/steve/Temporary/Build/Products/Debug/SOGraphDB-Mac Tests.xctest, NSLocalizedDescription=The bundle “SOGraphDB-Mac Tests” couldn’t be loaded because it is damaged or missing necessary resources.}
Any idea what the root cause can be?
The error seems realated to "Library not loaded: #rpath/libswiftAppKit.dylib"
Both (framework and test bundle) compile without any error or warning (in Beta2)
I had a similar problem, though mine was an iOS test target, linking to a Swift framework, that failed to run on Xcode 6 GM. The test target had run successfully on an early beta of Xcode 6, but the final version reported the runtime error: Library not loaded: #rpath/libswiftCore.dylib
I noticed that a newer project did not have the failure, so I compared the build settings and test code. I was able to resolve the problem with three steps:
The test target needs the "Embedded Target Contains Swift Code" setting to be YES. This tells the linker to add the Swift runtime libraries to the executable.
The test target needs an explicit value for the "Runpath Search Paths" build setting. This tells the loader where to find the Swift runtime libaries. I copied the following setting from a fresh new test target:
LD_RUNPATH_SEARCH_PATHS = $(inherited) #executable_path/../Frameworks #loader_path/../Frameworks
The test cases need to explicitly import any modules that are used by the linked framework. In my project, the framework used UIKit but the test cases only used my framework. When I added an explicit import UIKit to the test cases, the link problem went away.
Since I keep running into this issue whenever I mess with build settings, here's the cleanest answer I can provide as of Xcode 8b5:
If unit tests don't run on iOS, make sure you have:
Runpath Search Paths: #loader_path/Frameworks
If unit tests don't run on macOS, make sure you have:
Runpath Search Paths: #loader_path/../Frameworks
This will show up as LD_RUNPATH_SEARCH_PATHS in your pbxproj file. You can also add $(inherited) to make sure project-wide paths are added as well, but those are probably empty.
Lastly, I didn't need the executable_path/... settings, doesn't make a difference for me whether they're there or not for unit tests.
I had the same problem.
Ended up copying libswiftAppKit.dylib out of the Xcode application directory (I am using beta 3), into a directory that I could reference (not part of an application bundle), then adding the library to the "Link binary with libraries" setting for the test bundle. My tests then started working.
FYI, the path for the dylib was at '/Applications/Xcode6-Beta3.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/libswiftAppKit.dylib'
Probably not a good final solution, but it works for the interim.
My solution was to add a single file to my test target, AppKitTests.swift (or AppKitSpec.swift in my case), and all the file contains is:
// While I don't know why, The.framework is built linked to libswiftAppKit.
// Frameworks do not embed the Swift libraries themselves, it's up to the host
// app to include the necessary libraries. So here we are, including AppKit on
// behalf of The.framework so that the tests can run.
import AppKit
Oh, I also added AppKit to the test target's set of frameworks.
I had this occur to me in Beta 4 and it turned out that I had done it to myself without realizing it.
I had a Framework project called Fnord. My FnordTests target contained a couple of unit test classes that had import Fnord at the top of each file. For some reason Xcode was complaining about those imports and so I commented them out. This is when I started getting the same symptoms while trying to run my unit tests.
I noticed that the settings for my FnordTests target were such that the target would be linked with Fnord.framework, and I realized that it might not be able to do that with the aforementioned import Fnord statements diked-out.
So I put them back in, and everything went back to normal. Curiously, Xcode no longer showed those import statements as being problematic, but this is beta so I can forgive that.
I hope this helps someone.
I ran into the same issue, adding
import AppKit
in the Swift file fixed it