Xcode 抛出“atomic_notify_one<unsigned long>”不可用

问题描述

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

解决方法

这里没有注释掉鳍状肢,而是一个对我有用的解决方案。

将 Podfile 中的鳍状肢更新为如下所示

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

在 ios 文件夹中运行 pod repo update

最后,使用

更新您的项目 pod

pod install

,

今天iOS模拟器更新到iOS 14.5后,这个问题又出现了。 “Shared S Katre”发布的答案似乎是一个很好的解决方法。

因为 React-Native 是开源代码,我认为 iOS 上的任何重大更新肯定会带来突破性的变化。我想这些会在以后修复。

无论如何 - 问题似乎确实出在 Flipper 上,它用作 RN (https://reactnative.dev/blog/2020/03/26/version-0.62) 的调试工具。

如果你只需要构建你的项目,你可以简单地在你的 podfile 中注释掉flipper,然后像这样重新安装你的pod。

Podfile

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

接下来,重新安装您的 Pod。我 cd 进入项目的根目录并使用 npx。

$ npx pod-install

最后,尝试构建和运行您的项目:

$ npx react-native run-ios

更新:

根据评论,现在看起来已经修复了。如果你想要鳍状肢,你应该能够恢复你的 Podfile 并更新鳍状肢。

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

感谢 Stackers!

,
  1. 修复Podfile,如下图所示 enter image description here
  2. cd ios
  3. 删除 Pods 文件夹和 Podfile.lock
  4. pod 安装
  5. pod 更新
  6. cd .. && npx react-native run-ios
,

我必须在 AppDelegate.m 中评论所有 #ifdef FB_SONARKIT_ENABLED,将 hermes 设置为 false 并在 Podfile 中评论 Flipper。

毕竟删除Pods和Podfile.lock,然后pod install

,

如果有人仍然出现此错误(我刚刚更新了 Mac、Xcode 等),您可以在不禁用 Flipper 和 Hermes 的情况下修复构建;在 post_install 下的 Pod 文件中,只需添加(我在网络上的某个地方找到了它,并对其进行了更改以修复最新更新的新错误):

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","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,deadline)")
  end

在您的 target 之前添加

# 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
,

此错误是来自鳍状肢的错误。 Flipper 抛出了更多描述性较低的错误,我不得不在我的 podfile 中对其进行评论。评论后,此错误停止。

,

刚刚评论了这一行并解决了这个问题-

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

我在 XCode 12.5 中构建时遇到了同样的问题。如果暂时禁用 Flipper 不适合您,您可以降级到 XCode 12.4。这为我修好了。您可以在此处下载 XCode 12.4:https://developer.apple.com/download/more

,

您需要在 Podfile 中的 Flipper 代码下方注释:

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

我认为@opensw 提供的答案会起作用,但我找到了一些更强大的解决方案,这样它每次都可以与 pod install 一起使用,而无需删除 Pods 文件夹。 首先,在您的 Podfile 中更改添加/替换这一行

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

现在在上面几行中提到的最新版本中修复了 Flipper-folly 但是我们还需要处理 RCT 愚蠢的问题,为此,我们将使用 find_and_replace 函数。 这是我从 here

得到的新函数
# Define find-and-replace function
  def find_and_replace(dir,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

现在从安装后调用此函数,因此我们需要在 post_install do |installer| 中添加以下 2 个函数调用

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

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

这是我在 Github 中的答案

,

稍微扩展 Umang 和 opensw 的答案。

我更新了 find_and_replace 如下。请注意,我添加了 system("chmod +w " + name) 以修复 Permission denied @ rb_sysopen 错误。

def find_and_replace(dir,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

这是我的鳍状肢配置

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

至于修复文件,就我而言,在截至 4 月 30 日的最新版本中,只需在一处更新 DistributedMutex-inl.h

另外,请注意我是如何在函数名称前添加两个额外的空格符号的。这是必需的,因此 pod install 不会在后续调用中破坏代码。

  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

,

在你的 React Native 版本的基础上替换你 Podfile 中所有当前的翻转代码:

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

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

然后使用此更新 Pods 项目:

cd ios && pod install && cd ..