37

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

mcnk
  • 1,690
  • 3
  • 20
  • 29

13 Answers13

32

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
Denerator
  • 421
  • 5
  • 12
9

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.
Sultan Aslam
  • 5,600
  • 2
  • 38
  • 44
  • 2
    This should accepted the answer!. Save my day – Hitesh Surani Dec 09 '21 at 06:43
  • 1
    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. – xji Dec 24 '21 at 13:13
  • Also I don't think you're supposed to also disable the `react_native_post_install(installer)` part. – xji Dec 24 '21 at 13:21
6

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

Ammar Yousaf
  • 61
  • 1
  • 3
  • Theres no way this was the error... wow – Maximilian Dietel Oct 21 '22 at 18:42
  • 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. – Mike S. Nov 04 '22 at 20:06
5

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
Siddhant
  • 687
  • 1
  • 8
  • 15
  • this works for me, but dont know what is drawbacks for setting the " config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '9.0'" for 'RCT-Folly' ??? – Ebrahim Sayed Dec 09 '22 at 00:23
3

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
Vijay Kahar
  • 1,082
  • 1
  • 7
  • 20
  • you can find the version at https://cocoapods.org/pods/Flipper-Folly in "See Podspec", e.g. 2.6.10 right now – Dorian Feb 15 '22 at 20:16
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.

Karatekid430
  • 940
  • 11
  • 25
2

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
Dorian
  • 7,749
  • 4
  • 38
  • 57
2

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

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.

mdmostafa
  • 618
  • 9
  • 19
1

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

Noah Bar-Shain
  • 739
  • 4
  • 5
  • This worked although I find that the `Time.h` error resolution exposed more errors behind it. :-/ – Mike S. Nov 04 '22 at 20:10
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')

Zoe
  • 27,060
  • 21
  • 118
  • 148
Rasheed Qureshi
  • 1,215
  • 1
  • 11
  • 19
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.

Ishita Sinha
  • 2,168
  • 4
  • 25
  • 38
0

In the Time.h(RTC-Folly) file:

I changed __IPHONE_10_0 to __IPHONE_12_0 (as my target iOS version is 11) and got it working. I guess the same can be done for MAC_OS_X_VERSION_10_12 to MAC_OS_X_VERSION_10_15 if you are targeting macOS.

Leandro Ariel
  • 727
  • 8
  • 5