Integrating Firebase Crashlytics for tvOS without Cocoapods or XCFramework support
Whether you are using legacy build settings in XCode and unable to utilize XCFramework bundles, or Cocoapods for something like security; here is how I went about integrating Firebase Crashlytics for tvOS.
Problem
If you are in the same boat as I, you may have come across the following issues on the Firebase Github:
- Integrate FirebaseCrashlytic sdk without CocoaPods and without.xcFramework #5394
- Binary Firebase Frameworks for tvOS #4550
There is also the following SO post:
Although not provided, it gave me the lead to the solution, “I could not integrate Frameworks. So the solution I followed is adding of Source files provided in https://github.com/firebase/firebase-ios-sdk”. ~ Gangadhar
Solution
There are two ways to accomplish this. You can either clone the Firebase iOS SDK repo found here, and the repos for all other required dependencies. Or, a simpler option is to use Cocoapods to get the required dependencies in a sample project, and move over the source files. I will be demonstrating the latter. Cocoapod source files only include those used, instead of the entire library.
To get started, create a sample tvOS application and give it a pod file with your required dependencies. My Podfile
looked like this:
platform :tvos, '10.0'target 'TestProject' do
use_frameworks!
pod 'Firebase/Crashlytics'
end
After running pod install
in the project directory, you can then view the Podfile.lock
to view all the dependencies and versions. This can be useful as to know dependency version requirements should you go the source from repo approach.
Open up your sample app’s Pods folder, remove the Cocoapod generated files and directories, rename the folder as you wish (ex: “Libraries”), and copy, move, or rename the folder, and add it to your project directory and target.
Note: If your project is generated via CMake or some other build system and/or you would like this process automated, refer to the ruby script using xcodeproj
at the end of this article. You can than skip this section.
Once linked, you will have all the source files added to Build Phases -> Compile Sources
. If you went the repo route (which contains all library files, regardless if used), you will have the file GULSwizzledObject
. This file will throw an error regarding ARC should you have it globally enabled. You must pass the compiler flag of -fno-objc-arc
to resolve this. It is reflected in the attached xcodeproj
Ruby script.
Next, you will need to set the preprocessor macros. Without these you will get compilation errors. You can just look at the Cocoapods framework bundles to see the macros for each framework. Open your .xcworkspace
generated by the pod install and view the framework targets. On each one search for Preprocessor Macros
or find it under BuildSettings -> Apple Clang — Preprocessing
. Copy these into your project target, or use the below script.
Now you need to specify where these library header files can be found. Update your Header Search Paths
accordingly. I made this recursive and just specified my Libraries
folder.
Lastly, for build settings, set Enable Modules (C and Objective-C)
to YES
.
Firebase Setup
For the rest of the setup, basically just follow Firebase’s instructions on adding your GoogleService-Info.plist
, adding your shell script build phase, script and input files, and you should be good to go! All of this is reflect in the script below.
Ruby Script
This Ruby script can be easily altered to your needs and project structure. Change you target, paths, and deployment target as needed. This was made to work with some proprietary software so some assumptions are made. You can find the docs for xcodeproj
here. The script can be found here:
https://github.com/JavanPoirier/tvos-crashlytics-testproj/blob/master/xcodeproj.rb
Building
When building you may encounter some import errors or more specifically a “Lexical or Preprocessor Issue” errors. Fix these by changing the imports accordingly. Example, I did have to change line 22 of:
FirebaseCore/GoogleUtilities/Logger/Private/GULLogger.h
Testing
You can test your Firebase Crashlytics the exact same way as mentioned in the Firebase documentation. I simply added assert(NO)
into my app delegate’s applicationWillResignActive
lifecycle method to crash it simply by pressing the Siri button.
Note:assert(NO)
does NOT crash release builds, and thrown exceptions won’t necessarily report a crash. I was able to use to crash test my release build.
[self performSelector:@selector(die_die)];
More Obj-C options here.
Once deployed, remember to detach the XCode debugger. Otherwise crashes will not be sent to the Firebase Console.
Run and crash the app. Vigorously refresh your Firebase Console under Crashlytics… et voila!
If you are still not seeing crashes logged in the console but are getting debug logs, refer to Firebase’s documentation.
The TestProject used for this example is available here:
https://github.com/JavanPoirier/tvos-crashlytics-testproj
If you have questions or feedback I am all ears. If anyone knows of a better way to do this, hit me up. I hope this helps!