Mac Catalyst: Porting an app using Crashlytics / Firebase

If you’ve tried to port an app using Mac Catalyst, you have likely been confronted by a rather common problem: some pods are not compatible with macOS.

Crashlytics and Firebase are commonly the first to pop out an error on the screen because of their widespread usage.

ld: in /Users/REDACTED/Pods/Crashlytics/iOS/Crashlytics.framework/Crashlytics(CLSInternalReport.o), building for Mac Catalyst, but linking in object file built for iOS Simulator, file '/Users/REDACTED/Pods/Crashlytics/iOS/Crashlytics.framework/Crashlytics' for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Now, a solution could be to remove those libraries entirely from the project. But why remove an entire feature from your iOS/iPadOS app to port your app to Mac?

Would it not be easier to just not build those pods for the Mac architecture?

This is actually possible and fairly easy. Add the following snippet to your Podfile:

With cocoapods 1.8.4, I had to adapt @AncAinu's excellent answer as follows:

post_install do |installer|
  installer.pods_project.targets.each do |target|
    if target.name == "Pods-[Name of Project]"
      puts "Updating # to exclude Crashlytics/Fabric"
      target.build_configurations.each do |config|
        xcconfig_path = config.base_configuration_reference.real_path
        xcconfig = File.read(xcconfig_path)
        xcconfig.sub!('-framework "Crashlytics"', '')
        xcconfig.sub!('-framework "Fabric"', '')
        new_xcconfig = xcconfig + 'OTHER_LDFLAGS[sdk=iphone*] = -framework "Crashlytics" -framework "Fabric"'
        File.open(xcconfig_path, "w") { |file| file << new_xcconfig }
      end
    end
  end
end

And also, in the case of Crashlytics, change the run script build phase for Fabric to:

if [[$ARCHS != "x86_64"]]; then
  "$/Fabric/run" [your usual key]
fi

And execute a pod install to let the magic proceed.

The compilation error is gone. You might get different compilation errors because you are still using (as opposed to compiling) those pods in your macOS build.

To avoid that, simply frame your pod usage, including imports statements with:

#if !targetEnvironment(macCatalyst) 
// Code to exclude for your macOS app
#endif

Your application might now compile for macOS provided you have no other problems down the road. Good luck!



Updated on 28 December 2019 with a more recent answer for compatibility with Cocoapods 1.8.4