React Native IOS构建错误 - typedef重新定义不同类型('uint8_t'(又名'unsigned char')与'enum clockid_t')

39
升级React Native从0.61.5到0.63.2后,在IOS上使用Flipper会出错:typedef redefinition with different types ('uint8_t' (aka 'unsigned char') vs 'enum clockid_t')。在Github上有一些提议的解决方法,但是没有一个能够解决我的问题。https://github.com/facebook/flipper/issues/834。是否有人找到了解决方法?非常感谢。
14个回答

34
请注意,如果您启用了 "use_frameworks!",则 Flipper 将无法工作,您应该在 Podfile 中禁用下面几行代码。
  # use_flipper!
  # post_install do |installer|
  #   flipper_post_install(installer)
  # end

在 react-native 0.63.4 中需要注释掉以下行:

use_flipper!

post_install do |installer|

flipper_post_install(installer)

end

- Rajeev Kumar Verma
5
请确保在此之后再次运行“pod update”,否则构建仍将失败。 - Tosh

10

步骤1:

进入YOUR_PROJECT > ios > Podfile,然后注释掉以下几行代码:

  # use_flipper!()

  # post_install do |installer|
  #   react_native_post_install(installer)
  #   __apply_Xcode_12_5_M1_post_install_workaround(installer)
  # end

步骤2:

在完成步骤1后,您需要在YOUR_PROJECT > ios路径下运行 pod update 命令。

Bingo就完成了。


重要提示:

如果您在完成上述两个步骤后遇到一些错误,请执行以下步骤:

  1. 进入目录YOUR_PROJECT > ios > YOUR_PROJECT_NAME >并运行以下命令
  2. plutil ./Info.plist它将向您显示问题所在位置。
  3. 然后从您的文本编辑器中修复该问题。

3
这应该接受答案!救了我的一天。 - Hitesh Surani
1
这个方法可以行得通,但它只是禁用了应用程序的Flipper调试器,而这可能非常有用。这可能只是一个临时解决办法。 - xji
我认为你不应该禁用react_native_post_install(installer)部分。 - xji
2023年了,这个答案仍然是正确的呵呵 :) - undefined

7

项目所在的目录名称不应包含空格。否则会导致此错误。


这绝不可能是错误...哇 - Maximilian Dietel
这个解决方案对于某些问题是“一个答案”,但绝对不是这个问题的答案。我和作者遇到了同样的错误,在我们的应用程序目录中根本没有空格。感谢您抽出时间来尝试帮助,虽然如此。我不想打击任何新手的积极性。 - Mike S.

5

这是我针对React Native 0.65的解决方法。非常重要的是,folly 应链接到 9.0 版本。

post_install do |installer|
react_native_post_install(installer)
installer.pods_project.targets.each do |target|
  target.build_configurations.each do |config|
    config.build_settings.delete "IPHONEOS_DEPLOYMENT_TARGET"
  end
  case target.name
  when 'RCT-Folly'
    target.build_configurations.each do |config|
      config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '9.0'
    end
  end
 end
end

1
这对我来说是有效的,但不知道为什么将“config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] ='9.0'”设置为“RCT-Folly”的缺点是什么? - Ebrahim Sayed

4

首先,从您的项目中删除Flipper。

接下来,按照以下路径进行操作: 路径:"Your-Project-App/ios/Pods/RCT-Folly/folly/portability/Time.h"

将该代码替换为time.h。

/*
 * Copyright (c) Facebook, Inc. and its affiliates.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#pragma once

#include <stdint.h>
#include <time.h>

#include <folly/portability/Config.h>

// OSX is a pain. The XCode 8 SDK always declares clock_gettime
// even if the target OS version doesn't support it, so you get
// an error at runtime because it can't resolve the symbol. We
// solve that by pretending we have it here in the header and
// then enable our implementation on the source side so that
// gets linked in instead.
#if __MACH__ &&                                                       \
        ((!defined(TARGET_OS_OSX) || TARGET_OS_OSX) &&                \
         (MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_12)) || \
    (TARGET_OS_IPHONE)

#ifdef FOLLY_HAVE_CLOCK_GETTIME
#undef FOLLY_HAVE_CLOCK_GETTIME
#endif

#define FOLLY_HAVE_CLOCK_GETTIME 1
#define FOLLY_FORCE_CLOCK_GETTIME_DEFINITION 1

#endif

// These aren't generic implementations, so we can only declare them on
// platforms we support.
#if !FOLLY_HAVE_CLOCK_GETTIME && (defined(__MACH__) || defined(_WIN32))
#define CLOCK_REALTIME 0
#define CLOCK_MONOTONIC 1
#define CLOCK_PROCESS_CPUTIME_ID 2
#define CLOCK_THREAD_CPUTIME_ID 3

typedef uint8_t clockid_t;
extern "C" int clock_gettime(clockid_t clk_id, struct timespec* ts);
extern "C" int clock_getres(clockid_t clk_id, struct timespec* ts);
#endif

#ifdef _WIN32
#define TM_YEAR_BASE (1900)

extern "C" {
char* asctime_r(const tm* tm, char* buf);
char* ctime_r(const time_t* t, char* buf);
tm* gmtime_r(const time_t* t, tm* res);
tm* localtime_r(const time_t* t, tm* o);
int nanosleep(const struct timespec* request, struct timespec* remain);
char* strptime(
    const char* __restrict buf,
    const char* __restrict fmt,
    struct tm* __restrict tm);
time_t timelocal(tm* tm);
time_t timegm(tm* tm);
}
#endif

在这之后,请尝试通过Xcode运行应用程序,现在该应用程序无法成功运行,您会得到另一个错误。

第二个错误是:"Command PhaseScriptExecution failed with a nonzero exit code"。

第二个错误的解决方法如截图所示:

点击这里查看图片描述。


3

请使用以下代码更新你的Pod文件。

use_flipper!({ 'Flipper-Folly' => '2.3.0' }) # update this part
 post_install do |installer|
   flipper_post_install(installer)
 end

你可以在“查看Podspec”中找到版本,例如2.6.10,位于https://cocoapods.org/pods/Flipper-Folly。 - Dorian

3

对我来说,这个错误是因为我在 ios/Podfile 中做了以下操作:

  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '12.0'
    end
  end

  installer.pods_project.build_configurations.each do |config|
    config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '12.0'
  end

我只能假设将 "Folly" 目标的构建目标设置弄错了什么。一旦这些行从我的 Podfile 中删除,并运行 npx pod-install,构建就又可以正常工作了。


2

我需要指定版本:

  # https://github.com/facebook/flipper/releases
  # https://cocoapods.org/pods/Flipper-Folly
  # https://cocoapods.org/pods/OpenSSL-Universal
  use_flipper!({
    "Flipper" => "0.134.0",
    "Flipper-Folly" => "2.6.10",
    "OpenSSL-Universal" => "1.1.1100"
  })

对于完整的Podfile,这可能会有所帮助:

require_relative "../node_modules/expo/scripts/autolinking"
require_relative "../node_modules/react-native/scripts/react_native_pods"
require_relative "../node_modules/@react-native-community/cli-platform-ios/native_modules"

platform :ios, "12.0"

target "socializus" do
  use_expo_modules!

  config = use_native_modules!

  use_react_native!(
    path: config[:reactNativePath],
    hermes_enabled: false
  )

  # https://github.com/facebook/flipper/releases
  # https://cocoapods.org/pods/Flipper-Folly
  # https://cocoapods.org/pods/OpenSSL-Universal
  use_flipper!({
    "Flipper" => "0.134.0",
    "Flipper-Folly" => "2.6.10",
    "OpenSSL-Universal" => "1.1.1100"
  })

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

    installer.pods_project.targets.each do |target|
      target.build_configurations.each do |config|
        config.build_settings.delete "IPHONEOS_DEPLOYMENT_TARGET"
      end
    end
  end
end

2

我曾遇到与 RCT-Folly 相关的问题,并通过以下方法解决了它:

基本上,问题出在文件 ../node_modules/react-native/scripts/react_native_pods.rb 中。这是该文件的代码。

  # But... doing so caused another issue in Flipper:
  #   "Time.h:52:17: error: typedef redefinition with different types"
  # We need to make a patch to RCT-Folly - remove the `__IPHONE_OS_VERSION_MIN_REQUIRED` check.
  # See https://github.com/facebook/flipper/issues/834 for more details.
  time_header = "#{Pod::Config.instance.installation_root.to_s}/Pods/RCT-Folly/folly/portability/Time.h"
  `sed -i -e  $'s/ && (__IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_10_0)//' #{time_header}`


如果你编辑node_modules中的代码,.lock文件将会被更改。因此为了安全起见,你可以更新Podfile
Podfilepost_install do |installer|行后添加以下代码段,如下所示:
  • 添加以下代码行

    sed -i -e $'s/__IPHONE_10_0/__IPHONE_12_0/' Pods/RCT-Folly/folly/portability/Time.h

    target 'AwesomeProjectTests' do
        inherit! :complete
        # Pods for testing
      end
    
      # Enables Flipper.
      #
      # Note that if you have use_frameworks! enabled, Flipper will not work and
      # you should disable the next line.
      use_flipper!()
    
      post_install do |installer|
        `sed -i -e  $'s/__IPHONE_10_0/__IPHONE_12_0/' Pods/RCT-Folly/folly/portability/Time.h`
        react_native_post_install(installer)
        __apply_Xcode_12_5_M1_post_install_workaround(installer)
      end
    end
    
    1. 在项目的根目录下运行 cd ios

    2. 在终端中运行 pod deintegrate 命令,然后再使用命令 pod install 重新安装Pod

    3. 最后,在项目的根目录下运行命令 npx react-native run-ios 再次构建项目

    太棒了!我的问题已经得到了解决。


  • 0
    在 Time.h(RTC-Folly) 文件中:
    我将 __IPHONE_10_0 更改为 __IPHONE_12_0(因为我的目标 iOS 版本是 11),并使其正常工作。如果你的目标是 macOS,我想 MAC_OS_X_VERSION_10_12 到 MAC_OS_X_VERSION_10_15 也可以这样做。

    网页内容由stack overflow 提供, 点击上面的
    可以查看英文原文,
    原文链接