Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase error while configuring app - unrecognized selector sent to class

I'm using Firebase in an iOS app and have two separate Firebase projects, one for production and one for development. My two .plist files are GoogleService-Info.plist and GoogleService-Info-Dev.plist, which I have been able to select based on a flag set in Targets -> Build Settings -> Other Swift Flags.

Inside AppDelegate didFinishLaunchingWithOptions:

#if DEBUG
    let buildFor = "DEV"
#else
    let buildFor = "PROD"
#endif
let firebasePlistFileName = buildFor == "DEV" ? "GoogleService-Info-Dev" : "GoogleService-Info"
let firebaseOptions = FIROptions(contentsOfFile: NSBundle.mainBundle().pathForResource(firebasePlistFileName, ofType: "plist"))
FIRApp.configureWithOptions(firebaseOptions) // line causing new Firebase error

This has been working fine up until today, when I had a problem with another Cocoapod project. I think it started happening when I cleaned the Xcode project or deleted Derived Data folder:

dyld: Library not loaded: @rpath/OtherPod.framework/OtherPod
  Referenced from:
  /Users/me/Library/Developer/CoreSimulator/Devices/12345678-E1C4-480F-B1D9-C10823DEA810/data/Containers/Bundle/Application/AE7B6EB0-43AB-CCCC-BBBB-AAAA71BF/MyApp.app/MyApp
  Reason: image not found

I eventually resolved that by choosing my app under Targets -> General -> Linked Frameworks and Libraries, then added all of the choices inside the Workspace folder (7 other pod projects) and set those ones I added as optional. Ever since then, I've been facing the error described in the title of this post:

2017-02-10 17:19:29.660 MyApp[12639:182433] +[NSData gtm_dataByGzippingData:error:]: unrecognized selector sent to class 0x10a0442e8
2017-02-10 17:19:29.680 MyApp[12639:182433] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[NSData gtm_dataByGzippingData:error:]: unrecognized selector sent to class 0x10a0442e8'
*** First throw call stack:
(
  0   CoreFoundation                      0x0000000109d88d4b __exceptionPreprocess + 171
  1   libobjc.A.dylib                     0x00000001097f121e objc_exception_throw + 48
  2   CoreFoundation                      0x0000000109df8e44 +[NSObject(NSObject) doesNotRecognizeSelector:] + 132
  3   CoreFoundation                      0x0000000109d0e005 ___forwarding___ + 1013
  4   CoreFoundation                      0x0000000109d0db88 _CF_forwarding_prep_0 + 120
  5   MyApp                               0x0000000102d73c9d -[FIRNetwork postURL:payload:queue:usingBackgroundSession:completionHandler:] + 331
  6   MyApp                               0x0000000102d70e72 -[FIRClearcutLogger sendNextPendingRequestWithCompletionHandler:] + 570
  7   MyApp                               0x0000000102d70918 -[FIRClearcutLogger sendLogsWithCompletionHandler:] + 447
  8   libdispatch.dylib                   0x000000010a6ab978 _dispatch_call_block_and_release + 12
  9   libdispatch.dylib                   0x000000010a6d50cd _dispatch_client_callout + 8
  10  libdispatch.dylib                   0x000000010a6b2e17 _dispatch_queue_serial_drain + 236
  11  libdispatch.dylib                   0x000000010a6b3b4b _dispatch_queue_invoke + 1073
  12  libdispatch.dylib                   0x000000010a6b402b _dispatch_queue_override_invoke + 683
  13  libdispatch.dylib                   0x000000010a6b6385 _dispatch_root_queue_drain + 720
  14  libdispatch.dylib                   0x000000010a6b6059 _dispatch_worker_thread3 + 123
  15  libsystem_pthread.dylib             0x000000010aa3a712 _pthread_wqthread + 1299
  16  libsystem_pthread.dylib             0x000000010aa3a1ed start_wqthread + 13
)
libc++abi.dylib: terminating with uncaught exception of type NSException

I have tried a lot of different fixes, including adding to the Link Binary with Libraries, adding to the Other Linker Flags, and none of them have worked.

What could the unrecognized selector possibly be, and how would I change/remove it? Could this issue be due to the earlier one I was facing (library not loaded)?

For clarification, when the unrecognized selector sent to class error happens, the Xcode debug navigator is focused on Thread 7, with the FIRApp.configureWithOptions(firebaseOptions) line being highlighted.

Update

I found a temporary fix by reverting to a previous git commit (cloned my repository into a separate directory), then replacing the majority of the project contents from that old commit with the current error-producing copy, including the App-Name folder within root directory, App-Name.xcodeproj, and App-Name.xcworkspace. I only tested on the simulator (iPhone 7 running iOS 10.2), and that worked. I then successfully submitted a build to iTunes Connect and was able to run that build on my device (iPhone 5c with 10.2.1), but after deleting that and attempting to run a build from Xcode, I got the same error again. However, the error did not occur while running on the simulator. This is in contrast to the initial error scenario as it occurred on both physical device and simulator.

This made me remember that the stack trace I initially posted was that of running the app on the simulator. Running it on the device produced less output, specifically the content after *** First throw call stack: is only (0x1d01cdf7 0x1c27f077 0x1d022467 0x1d020579 0x1cf453d8 0x31ff3f 0x31d653 0x31d05d 0x1c57d57 0x1c63e63 0x1c5b205 0x1c64391 0x1c65d9f 0x1c65ba7 0x1c877937 0x1c877490) instead of the more descriptive output with file/function names.

like image 521
Pat Needham Avatar asked Feb 10 '17 22:02

Pat Needham


3 Answers

Earlier, I have faced the same issue, I fixed the issue by reinstalling pod.

Please refer to the below-mentioned steps to resolve the issue.

Please make sure that you have added Add two-parameter in Other Linker Flags.

$(inherited)
-ObjC

Cocoapods:

Just install cocoa-pods again in the project. Please refer below command for remove and install pods.

Remove all Framework from project using below command.

pod deintegrate
pod clean

- Install framework using below pod command

pod install

Manual:

If you have added framework Manual in the project then remove it and add it into the project again.

Issue:

You have faced reference issue in your project (framework not found at Specific Directory).

Hit the Clean and Build project. Everything worked as expected

like image 84
Hitesh Surani Avatar answered Nov 12 '22 13:11

Hitesh Surani


Make sure GTMNSData+zlib.m from the GoogleToolboxForMac pod is still being built and linked into your app.

enter image description here

Make sure that -ObjC and -framework GoogleToolboxForMac is in the Link log:

enter image description here

like image 4
Paul Beusterien Avatar answered Nov 12 '22 13:11

Paul Beusterien


To anyone experiencing this problem, while trying to add the firebase frameworks manually. I had the same issue, which was caused by having different versions of firebase. I tried to add additional frameworks as the readme suggested, but experienced the above mentioned error.

I resolved this by removing all the firebase frameworks from the project and build phases. Downloaded the newest version, and re-added all frameworks to the project, and the problem was resolved.

like image 1
martin meincke Avatar answered Nov 12 '22 13:11

martin meincke