[Fixed] xcode firebase message error OSAtomicCompareAndSwapPtrBarrier – Firebase

by
Ali Hasan
axios firebase ionic3

Quick Fix: Pin an older working version of ‘Protobuf’ in your Podfile:

target 'YourTarget' do
  project 'YourProject'
  ... 
  pod 'Protobuf', '= 3.22.1' # Pinned version for Firebase Messaging
end

Remove Podfile.lock and run pod install.

The Solutions:

Solution 1: Update Podfile

To fix the issue related to the Protobuf library in Firebase Messaging, modify your Podfile as follows:

...
target 'YourTarget' do
  project 'YourProject'
  ...
  pod 'Protobuf', '= 3.22.1' # Pinned version for Firebase Messaging
end

This will pin the Protobuf library to version 3.22.1, which is compatible with the current Firebase Messaging version.

Once you have updated the Podfile, remove the Podfile.lock file and run pod install to install the correct version of the Protobuf library.

Solution 3: Use #include <libkern/OSAtomic.h>

To resolve the error, you can include the header file <libkern/OSAtomic.h> in the files where the error occurs. This will import the declaration of the OSAtomicCompareAndSwapPtrBarrier function, which is required for the code to compile successfully.

Here’s how to import the header file:

#include <libkern/OSAtomic.h>

Solution 4: Update Firebase related libraries

Upgrade all Firebase related libraries to the latest versions. For example, update the following dependencies in your project’s package.json:

  "@react-native-firebase/analytics": "^17.5.0",
  "@react-native-firebase/app": "^17.5.0",
  "@react-native-firebase/crashlytics": "^17.5.0",
  "@react-native-firebase/dynamic-links": "^7.5.1",
  "@react-native-firebase/firestore": "^17.5.0",
  "@react-native-firebase/messaging": "^17.5.0",
  "@react-native-firebase/remote-config": "^17.5.0",

Q&A

How to solve the problem of ‘conflicting types for OSAtomicCompareAndSwapPtrBarrier’ in Firebase Messaging library?

Pin a previous working version of ‘Protobuf’ in your Podfile.

Which version of Protobuf should be installed to solve this issue?

Install Protobuf version 3.22.1.

Which version of @react-native-firebase/messaging library is compatible?

Use version 17.5.0 or above.