将 React Native 从 0.61.5 升级到 0.63.2 后,
Flipper
在 IOS 上导致错误为 typedef redefinition with different types ('uint8_t' (aka 'unsigned char') vs 'enum clockid_t')
在github上有一些建议的答案,但没有一个解决了我的问题https://github.com/facebook/flipper/issues/834
有人知道如何解决这个问题吗?
非常感谢
请注意,如果您有 use_frameworks!启用后,Flipper 将无法工作并且 您应该在 Podfile 中禁用接下来的几行。
# use_flipper!
# post_install do |installer|
# flipper_post_install(installer)
# end
第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 步之后,您必须在
pod update
路径上运行 YOUR_PROJECT > ios
命令。
宾果游戏完成了。
重要
如果执行上述 2 个步骤后出现一些错误,
YOUR_PROJECT > ios > YOUR_PROJECT_NAME >
并运行此命令plutil ./Info.plist
它会告诉您问题出在哪里。目录名称中不应包含项目所在的空格。 这也可能导致此错误。
这就是我解决 React Native 0.65 的问题。非常重要的是,愚蠢应该链接到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
使用以下代码更新您的 pod 文件。
use_flipper!({ 'Flipper-Folly' => '2.3.0' }) # update this part
post_install do |installer|
flipper_post_install(installer)
end
我需要指定版本:
# 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
首先,从项目中删除 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运行应用程序,现在应用程序无法成功运行,您又遇到了另一个错误
第二个错误是:“命令 PhaseScriptExecution 失败,退出代码非零”
屏幕截图中的第二个错误解决方案,
我遇到了与
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
。
添加这行代码
sed -i -e $'s/__IPHONE_10_0/__IPHONE_12_0/' Pods/RCT-Folly/folly/portability/Time.h
在
post_install do |installer|
中的 Podfile
行之后,如以下代码片段
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
在项目根文件夹上运行
cd ios
在终端中运行
pod deintergrate
并使用命令 pod install
再次安装 pod
最后,在项目根文件夹上运行命令
npx react-native run-ios
再次构建项目
宾果!我的问题已按预期得到解决。
对我来说,发生这个错误是因为我在
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
后,构建再次开始工作。
我从react-native 0.65升级到0.68。
删除 Pods 和 Podfile.lock,然后从我的 iOS 目录中运行
pod update
。感谢@Sultan Aslam 提及
pod update
就我而言,我的 XCode 版本是 11.5,它不支持 Flipper 中的更新内容。将我的 XCode 更新到版本 12 立即修复了该问题。
如果您不想从应用程序中删除 Flipper,请执行此解决方案。
你的 pod.file 像这样
add_flipper_pods!('Flipper' => '0.74.0')
通过这样做来升级 Flipper-Folly
删除此行
add_flipper_pods!('Flipper' => '0.74.0')
添加此行
add_flipper_pods!('Flipper-Folly' => '2.3.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 执行相同的操作。