React Native Build Error on IOS - typedef redefinition with different types ('uint8_t' (aka 'unsigned char') vs 'enum clockid_t')
Asked Answered
F

14

45

After upgrading React Native from 0.61.5 to 0.63.2, Flipper causes an error on IOS as typedef redefinition with different types ('uint8_t' (aka 'unsigned char') vs 'enum clockid_t')

On github there are a few proposed answers but none of them solved my problem https://github.com/facebook/flipper/issues/834

Is there anyone figured out how to solve this?

Many thanks

Falcongentle answered 12/8, 2020 at 12:24 Comment(0)
H
35

Note that if you have use_frameworks! enabled, Flipper will not work and you should disable these next few lines in your Podfile.

  # use_flipper!
  # post_install do |installer|
  #   flipper_post_install(installer)
  # end
Harquebus answered 3/3, 2021 at 8:36 Comment(2)
With react-native 0.63.4 need to comment below line # use_flipper! # post_install do |installer| # flipper_post_install(installer) # endCrusade
Make sure you run pod update again after, otherwise build will still failSavor
F
11

STEP 1:

Go to YOUR_PROJECT > ios > Podfile and then comment these lines

  # use_flipper!()

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

STEP 2:

after step 1 you have to run pod update command on YOUR_PROJECT > ios path.

Bingo its done.


IMPORTANT

In case you get some errors after doing above 2 steps,

  1. GO to YOUR_PROJECT > ios > YOUR_PROJECT_NAME > and run this command
  2. plutil ./Info.plist it will show you where the issue is.
  3. Then fix that issue from your text editor.
Faina answered 6/12, 2021 at 7:14 Comment(4)
This should accepted the answer!. Save my dayGradatim
This will work, but it will just disable the Flipper debugger for the app right, which could be very useful. Might be a temporary workaround.Spin
Also I don't think you're supposed to also disable the react_native_post_install(installer) part.Spin
2023 and still this one is the correct answer hehe :)Chud
L
9

This is what solves for me for react native 0.65. It is very important that folly should link to 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
Loxodrome answered 17/9, 2022 at 15:58 Comment(2)
this works for me, but dont know what is drawbacks for setting the " config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '9.0'" for 'RCT-Folly' ???Bonnie
I am following this but sadly Xcode throws linker command failed and gives no additional details. I am on M2 Mac running Xcode 15 and using RN 0.65.1Outfield
B
8

Directories name should not have space in which project exists. This can also cause this error.

Bangle answered 15/8, 2022 at 4:31 Comment(2)
Theres no way this was the error... wowReligieux
This solution is "an answer" for some issues, but definitely not this issue. I have the same error as the author and there are no spaces whatsoever in our app directory. Thanks for taking the time to try helping, though. I don't want to discourage any newcomers.Flabellum
A
7

First, remove the Flipper from your project.

After you go with this path. Path: "Your-Project-App/ios/Pods/RCT-Folly/folly/portability/Time.h"

Replace this code 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

After that, Please try to run the application via Xcode, Now the application can't run successfully you got another error

2nd Error is: "Command PhaseScriptExecution failed with a nonzero exit code"

2nd Error solution in the screenshot,

enter image description here

Adulterer answered 4/11, 2022 at 7:4 Comment(1)
This worked for me, but here is other permanent solution?Dap
H
4

Update your pod file with below code.

use_flipper!({ 'Flipper-Folly' => '2.3.0' }) # update this part
 post_install do |installer|
   flipper_post_install(installer)
 end
Hypotaxis answered 2/3, 2021 at 13:18 Comment(1)
you can find the version at cocoapods.org/pods/Flipper-Folly in "See Podspec", e.g. 2.6.10 right nowKep
K
3

I needed to specify the versions:

  # 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"
  })

And for a full Podfile, it might help:

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
Kep answered 15/2, 2022 at 20:30 Comment(0)
C
3

For me, this error occurred because I was doing in the ios/Podfile the following:

  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

I can only assume that setting the build target of the Folly target was messing with something. Once these lines were removed from my Podfile and npx pod-install was run, the build worked again.

Catechin answered 28/12, 2022 at 5:55 Comment(0)
N
2

I faced the same problem with RCT-Folly and solved the issue following the ways below:

Basically, it comes from ../node_modules/react-native/scripts/react_native_pods.rb file. Here is the code of that file.

  # 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}`

If you edit the code in node_modules, the .lock file will be changed. So to be safe, you can update the Podfile.

  1. Add this line of code

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

    after the post_install do |installer| line in Podfile like the following code snippet

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. Run cd ios on the project root folder

  2. Run pod deintergrate in the terminal and install pod again with the command pod install

  3. Finally, build the project again with running the command npx react-native run-ios on the project root folder

Bingo! My issue has been solved as expected.

Nicolnicola answered 1/12, 2022 at 9:5 Comment(0)
K
0

if you do not want to remove Flipper from your app then go through this solution.

your pod.file like this

add_flipper_pods!('Flipper' => '0.74.0')

upgrade Flipper-Folly by doing this

remove this line add_flipper_pods!('Flipper' => '0.74.0')

add this line add_flipper_pods!('Flipper-Folly' => '2.3.0')

Kef answered 19/5, 2021 at 11:52 Comment(0)
C
0

In my case, my XCode version was 11.5 and it was not supporting something newer in Flipper. Updating my XCode to version 12 fixed it immediately.

Catarinacatarrh answered 7/6, 2021 at 10:15 Comment(0)
P
0

I upgraded from react-native 0.65 to 0.68.
Deleted Pods and Podfile.lock and then ran pod update from within my iOS directory.
Didn't have to change any other code.

Thanks to @Sultan Aslam for mentioning pod update

Pilfer answered 5/8, 2022 at 0:14 Comment(1)
This worked although I find that the Time.h error resolution exposed more errors behind it. :-/Flabellum
G
0

Downgrading node to 16.13.0 worked for me, then remove node modules and pods then reinstall it

Gritty answered 16/10, 2023 at 9:19 Comment(0)
L
0

Open Time.h File

Go to Line 52 to 55 and Update from

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

to this

typedef clockid_t clockid;
extern "C" int clock_gettime(clockid clk_id, struct timespec* ts);
extern "C" int clock_getres(clockid clk_id, struct timespec* ts);
#endif
Laue answered 29/5 at 5:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.