Xcode 抛出的“ atom_tification_one < unsignedlong >”不可用

我在 Mac 上安装了 Xcode 12,尝试构建完美运行在 android 上的本地应用程序,然后得到了 'atomic_notify_one<unsigned long>' is unavailable。这是我从错误中得到的最多信息。

54539 次浏览

This error was an error from flipper. Flipper threw several more less descriptive errors that I had to comment it on my podfile. After commenting, this error stopped.

  1. Fix Podfile as shown in below image enter image description here
  2. cd ios
  3. delete Pods folder and Podfile.lock
  4. pod install
  5. pod update
  6. cd .. && npx react-native run-ios

You need to comment below Flipper code in Podfile:

use_flipper!
post_install do |installer|
flipper_post_install(installer)
end

This issue happened again today after the iOS simulators were updated to iOS 14.5. The answer posted by "Shared S Katre" seems to be a good work-around.

Because React-Native is open source code, I would think that any big updates on iOS can definitely bring about breaking changes. I imagine those will be fixed later.

Anyways - the issue does seem to be with Flipper, which serves as a debugging tool for RN (https://reactnative.dev/blog/2020/03/26/version-0.62).

If you just need to get your project to build, you can just simply comment out flipper in your podfile, and re-install your pods like so.

Podfile

# Enables Flipper.
#
# Note that if you have use_frameworks! enabled, Flipper will not work and
# you should disable the next line.
# use_flipper!()

Next, re-install your pods. I cd'd into the root of the project and used npx.

$ npx pod-install

Last, try building and running your project:

$ npx react-native run-ios

Update:

Per the comments, looks like this has been fixed now. If you want flipper, you should be able to revert your Podfile and update flipper.

See: https://stackoverflow.com/a/67314652/9906042

Thanks Stackers!

I have to comment all #ifdef FB_SONARKIT_ENABLED in AppDelegate.m, set hermes to false and comment Flipper in Podfile.

After all, delete Pods and Podfile.lock, then pod install

I had the same issue when building in XCode 12.5. If temporarily disabling Flipper is not an option for you, you can downgrade to XCode 12.4. This fixed it for me. You can download XCode 12.4 here: https://developer.apple.com/download/more

If someone has still this error (I have just updated Mac, Xcode, etc), you can fix the build without disabling Flipper and Hermes; in your Pod file under post_install just add (I have found it somewhere on the web and changed it to fix new errors with the last updates):

post_install do |installer|
flipper_post_install(installer)
react_native_post_install(installer)


# # to build for the simulator on Apple M1
# installer.pods_project.targets.each do |target|
#   target.build_configurations.each do |config|
#     # disables arm64 builds for the simulator
#     config.build_settings['EXCLUDED_ARCHS[sdk=iphonesimulator*]'] = 'arm64'
#   end
# end


## Fix for XCode 12.5 & RN 0.62.2 - See https://github.com/facebook/react-native/issues/28405
find_and_replace("../node_modules/react-native/React/CxxBridge/RCTCxxBridge.mm",
"_initializeModules:(NSArray<id<RCTBridgeModule>> *)modules", "_initializeModules:(NSArray<Class> *)modules")


find_and_replace("../node_modules/react-native/ReactCommon/turbomodule/core/platform/ios/RCTTurboModuleManager.mm",
"RCTBridgeModuleNameForClass(strongModule))", "RCTBridgeModuleNameForClass(Class(strongModule)))")


## Fix for Flipper-Folly on iOS 14.5
find_and_replace("Pods/Flipper-Folly/folly/synchronization/DistributedMutex-inl.h",
"atomic_notify_one(state)", "folly::atomic_notify_one(state)")


find_and_replace("Pods/Headers/Private/RCT-Folly/folly/synchronization/DistributedMutex-inl.h",
"atomic_notify_one(state)", "folly::atomic_notify_one(state)")


find_and_replace("Pods/Flipper-Folly/folly/synchronization/DistributedMutex-inl.h",
"atomic_wait_until(&state, previous | data, deadline)", "folly::atomic_wait_until(&state, previous | data, deadline)")
end

Before your target, add

# fixes for last Mac updates
def find_and_replace(dir, findstr, replacestr)
Dir[dir].each do |name|
text = File.read(name)
replace = text.gsub(findstr,replacestr)
if text != replace
puts "Fix: " + name
File.open(name, "w") { |file| file.puts replace }
STDOUT.flush
end
end
Dir[dir + '*/'].each(&method(:find_and_replace))
end

Instead of commenting out flipper here is a solution that worked for me.

Update flipper in your Podfile to look like this

use_flipper!({ 'Flipper-Folly' => '2.5.3', 'Flipper' => '0.87.0', 'Flipper-RSocket' => '1.3.1' })

Run pod repo update inside the ios folder

And finally, update your project pods using

pod install

I think the answer provided by @opensw will work but I have found something more enhanced solution so that it works with pod install every time without deleting the Pods folder. First of all, change add/Replace this line in your Podfile

use_flipper!({ 'Flipper-Folly' => '2.5.3', 'Flipper' => '0.87.0', 'Flipper-RSocket' => '1.3.1' })

Now in the latest versions mentioned in the above lines fixes an issue with the Flipper-folly But We also need to take care of the RCT-folly and for that, we will use the find_and_replace function. Here is the new function which I got from the here

# Define find-and-replace function
def find_and_replace(dir, findstr, replacestr)
Dir[dir].each do |name|
text = File.read(name)
replace = text.gsub(findstr,replacestr)
replaced = text.index(replacestr)
if replaced == nil && text != replace
puts "Fix: " + name
File.open(name, "w") { |file| file.puts replace }
STDOUT.flush
end
end
Dir[dir + '*/'].each(&method(:find_and_replace))
end

Now call this function from the post-install so we will need to add the following 2 function calls inside post_install do |installer|

 find_and_replace("Pods/RCT-Folly/folly/synchronization/DistributedMutex-inl.h",
"atomic_notify_one(state)", "folly::atomic_notify_one(state)")


find_and_replace("Pods/RCT-Folly/folly/synchronization/DistributedMutex-inl.h",
"atomic_wait_until(&state, previous | data, deadline)", "folly::atomic_wait_until(&state, previous | data, deadline)")

Here is my Answer in Github

To expand a little bit on the Umang's and opensw answers.

I have updated find_and_replace as following. Note, I have added system("chmod +w " + name) that fixes Permission denied @ rb_sysopen error.

def find_and_replace(dir, findstr, replacestr)
Dir[dir].each do |name|
text = File.read(name)
replace = text.gsub(findstr,replacestr)


if text != replace
puts "Fix: " + name
system("chmod +w " + name)
File.open(name, "w") { |file| file.puts replace }
STDOUT.flush
end
end
Dir[dir + '*/'].each(&method(:find_and_replace))
end

Here is my flipper configuration

use_flipper!({ 'Flipper' => '0.87.0', 'Flipper-Folly' => '2.5.3', 'Flipper-RSocket' => '1.3.1' })

And as for fixing files, in my case, on the most recent versions as of Apr. 30th it is enough to update DistributedMutex-inl.h in only one place.

Also, note how I added two extra whitespace symbols before the function name. This is needed so pod install won't break code on the subsequent calls.

  post_install do |installer|
flipper_post_install(installer)
react_native_post_install(installer)


find_and_replace("Pods/RCT-Folly/folly/synchronization/DistributedMutex-inl.h",
"  atomic_notify_one(state);", "  folly::atomic_notify_one(state);")
end


just commented this line and solved this issue-

  # use_flipper!
# post_install do |installer|
#   flipper_post_install(installer)
# end

Replace all current flipper code in your Podfile with this base on your React Native version:

add_flipper_pods!({ 'Flipper-Folly' => '2.5.3', 'Flipper' => '0.87.0', 'Flipper-RSocket' => '1.3.1' })

or

use_flipper!({ 'Flipper-Folly' => '2.5.3', 'Flipper' => '0.87.0', 'Flipper-RSocket' => '1.3.1' })

Then update for Pods project using this:

cd ios && pod install && cd ..

I had this same issue upgrading a project from RN 0.63 to 0.64 (and using Xcode 12.5), but the top voted answer didn't solve the issue for me, and I was keen to avoid any additional scripts.

I noticed in the Upgrade Helper some changes in the podfile - particularly the change from flipper_post_install(installer) to react_native_post_install(installer). I made this change and blitzed my pods directory and then ran pod install --repo-update and this fixed it for me :)

I also noticed a patch being run for the DistributedMutex file (which was the file in question) after the pods were installed, so it seems to me that this should be the correct fix

Bonus: This also allowed me to remove the old flipper_post_install script I had at the top of my podfile from a previous upgrade

replace atomic_nofiy_one with folly::atomic_notify_one, the full podfile is blow:

platform :ios, '9.0'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'


def add_flipper_pods!
version = '~> 0.33.1'
pod 'FlipperKit', version, :configuration => 'Debug'
pod 'FlipperKit/FlipperKitLayoutPlugin', version, :configuration => 'Debug'
pod 'FlipperKit/SKIOSNetworkPlugin', version, :configuration => 'Debug'
pod 'FlipperKit/FlipperKitUserDefaultsPlugin', version, :configuration => 'Debug'
pod 'FlipperKit/FlipperKitReactPlugin', version, :configuration => 'Debug'
end


# Post Install processing for Flipper
def flipper_post_install(installer)
installer.pods_project.targets.each do |target|
if target.name == 'YogaKit'
target.build_configurations.each do |config|
config.build_settings['SWIFT_VERSION'] = '4.1'
end
end
end
end


target 'AwesomeProject' do
# Pods for AwesomeProject
pod 'FBLazyVector', :path => "../node_modules/react-native/Libraries/FBLazyVector"
pod 'FBReactNativeSpec', :path => "../node_modules/react-native/Libraries/FBReactNativeSpec"
pod 'RCTRequired', :path => "../node_modules/react-native/Libraries/RCTRequired"
pod 'RCTTypeSafety', :path => "../node_modules/react-native/Libraries/TypeSafety"
pod 'React', :path => '../node_modules/react-native/'
pod 'React-Core', :path => '../node_modules/react-native/'
pod 'React-CoreModules', :path => '../node_modules/react-native/React/CoreModules'
pod 'React-Core/DevSupport', :path => '../node_modules/react-native/'
pod 'React-RCTActionSheet', :path => '../node_modules/react-native/Libraries/ActionSheetIOS'
pod 'React-RCTAnimation', :path => '../node_modules/react-native/Libraries/NativeAnimation'
pod 'React-RCTBlob', :path => '../node_modules/react-native/Libraries/Blob'
pod 'React-RCTImage', :path => '../node_modules/react-native/Libraries/Image'
pod 'React-RCTLinking', :path => '../node_modules/react-native/Libraries/LinkingIOS'
pod 'React-RCTNetwork', :path => '../node_modules/react-native/Libraries/Network'
pod 'React-RCTSettings', :path => '../node_modules/react-native/Libraries/Settings'
pod 'React-RCTText', :path => '../node_modules/react-native/Libraries/Text'
pod 'React-RCTVibration', :path => '../node_modules/react-native/Libraries/Vibration'
pod 'React-Core/RCTWebSocket', :path => '../node_modules/react-native/'


pod 'React-cxxreact', :path => '../node_modules/react-native/ReactCommon/cxxreact'
pod 'React-jsi', :path => '../node_modules/react-native/ReactCommon/jsi'
pod 'React-jsiexecutor', :path => '../node_modules/react-native/ReactCommon/jsiexecutor'
pod 'React-jsinspector', :path => '../node_modules/react-native/ReactCommon/jsinspector'
pod 'ReactCommon/callinvoker', :path => "../node_modules/react-native/ReactCommon"
pod 'ReactCommon/turbomodule/core', :path => "../node_modules/react-native/ReactCommon"
pod 'Yoga', :path => '../node_modules/react-native/ReactCommon/yoga', :modular_headers => true


pod 'DoubleConversion', :podspec => '../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec'
pod 'glog', :podspec => '../node_modules/react-native/third-party-podspecs/glog.podspec'
pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec'


target 'AwesomeProjectTests' do
inherit! :complete
# Pods for testing
end


use_native_modules!


# Enables Flipper.
#
# Note that if you have use_frameworks! enabled, Flipper will not work and
# you should disable these next few lines.
add_flipper_pods!
post_install do |installer|
flipper_post_install(installer)
## Fix for XCode 12.5 beta
find_and_replace("../node_modules/react-native/React/CxxBridge/RCTCxxBridge.mm",
"_initializeModules:(NSArray<id<RCTBridgeModule>> *)modules", "_initializeModules:(NSArray<Class> *)modules")
find_and_replace("../node_modules/react-native/ReactCommon/turbomodule/core/platform/ios/RCTTurboModuleManager.mm",
"RCTBridgeModuleNameForClass(strongModule))", "RCTBridgeModuleNameForClass(Class(strongModule)))")
find_and_replace("Pods/Flipper-Folly/folly/synchronization/DistributedMutex-inl.h",
"  atomic_notify_one(state);", "  folly::atomic_notify_one(state);")
end
end


target 'AwesomeProject-tvOS' do
# Pods for AwesomeProject-tvOS


target 'AwesomeProject-tvOSTests' do
inherit! :search_paths
# Pods for testing
end
end


def find_and_replace(dir, findstr, replacestr)
Dir[dir].each do |name|
text = File.read(name)
replace = text.gsub(findstr,replacestr)


if text != replace
puts "Fix: " + name
File.open(name, "w") { |file| file.puts replace }
STDOUT.flush
end
end
Dir[dir + '*/'].each(&method(:find_and_replace))
end