Skip to content

fix: iOS build error on React Native v0.81#19

Merged
chrispader merged 6 commits into
margelo:mainfrom
war-in:fix/ios-build-issue-RN-81
Oct 8, 2025
Merged

fix: iOS build error on React Native v0.81#19
chrispader merged 6 commits into
margelo:mainfrom
war-in:fix/ios-build-issue-RN-81

Conversation

@war-in

@war-in war-in commented Sep 16, 2025

Copy link
Copy Markdown
Contributor

While migrating Expensify/App to the newest React Native version (v0.81), I got a build issue where react-native-release-profiler couldn't find enableSamplingProfiler

It turned out that we should use the new approach (IHermesRootAPI) to access the functions

IHermesRootAPI *api = castInterface<IHermesRootAPI>(makeHermesRootAPI());
api->enableSamplingProfiler();

Unfortunately, I wasn't able to build the example app due to some issues with pods (I followed the CONTRIBUTING.md file), so I'd appreciate some help 🙏

cc @chrispader as you're actively working on the Expensify/App

@war-in

war-in commented Sep 16, 2025

Copy link
Copy Markdown
Contributor Author

FYI, I'm worried that this is not backwards-compatible :/ I tried adding those changes to the project with RN v0.79 and the build failed

@chrispader

Copy link
Copy Markdown
Member

I'll look into this in a bit and see if we can make this backwards-compatible. Thanks already!

cursor[bot]

This comment was marked as outdated.

@chrispader

Copy link
Copy Markdown
Member

Thanks for your PR @war-in !

Unfortunately, I wasn't able to build the example app due to some issues with pods (I followed the CONTRIBUTING.md file), so I'd appreciate some help 🙏

The broken example project build was addressed in #21 and #22

FYI, I'm worried that this is not backwards-compatible :/ I tried adding those changes to the project with RN v0.79 and the build failed

I just made your changes backwards-compatible. I'll create a PR with the new react-native-release-profiler in https://github.com/Expensify/App soon!

@war-in

war-in commented Oct 8, 2025

Copy link
Copy Markdown
Contributor Author

@chrispader That's great! Thank you! Please tag me under the E/App PR once it's ready 🙏

@chrispader

Copy link
Copy Markdown
Member

Just tested this PR on both RN0.72 and RN0.81 and it builds fine!

@chrispader chrispader merged commit 7bcecb4 into margelo:main Oct 8, 2025
1 check passed
@yolpsoftware

Copy link
Copy Markdown

Thanks for the fix @chrispader. However, this still fails on our app (after migration to Expo 54).

Maybe relevant parts of my package.json:

    "react": "19.1.0",
    "react-dom": "19.1.0",
    "react-native": "0.81.4",
...
    "react-native-release-profiler": "^0.4.1",
...
    "@react-native-community/cli": "^20.0.2",

I examined your fix in more detail (first lines of ReleaseProfiler.mm):

...
#ifdef __has_include
#if __has_include(<React/ReactNativeVersion.h>)
#include <React/ReactNativeVersion.h>
#define IS_RN_VERSION_0_81_OR_HIGHER                                           \
  (REACT_NATIVE_VERSION_MAJOR > 0 ||                                           \
   (REACT_NATIVE_VERSION_MAJOR == 0 && REACT_NATIVE_VERSION_MINOR >= 81))
#else
#define IS_RN_VERSION_0_81_OR_HIGHER false
#endif
...

Here, the ifdef evaluates to true in my codebase, but the if to false, which leads to IS_RN_VERSION_0_81_OR_HIGHER being set to false.

Where is that ReactNativeVersion.h coming from? What could be the reasons why it's not present in my codebase?

@yolpsoftware

Copy link
Copy Markdown

Seems the reason for my problem is using Expo SDK 54, which uses precompiled XCFrameworks for iOS to speed up build times. However, this means that certain header files like ReactNativeVersion.h are not present in a Expo 54 codebase.

A quick fix for this might be to add the following to your app.json:

{
  "expo": {
    "plugins": [
      ["expo-build-properties", {
        "ios": {
          "buildReactNativeFromSource": true
        }
      }]
    ]
  }
}

This disables the precompiled XCFrameworks. However, when trying that out, I still ran into the same errors.

Any idea? Has anyone managed to get 0.4.1 running with Expo 54?

@chrispader

Copy link
Copy Markdown
Member

Seems the reason for my problem is using Expo SDK 54, which uses precompiled XCFrameworks for iOS to speed up build times. However, this means that certain header files like ReactNativeVersion.h are not present in a Expo 54 codebase.

A quick fix for this might be to add the following to your app.json:

{
  "expo": {
    "plugins": [
      ["expo-build-properties", {
        "ios": {
          "buildReactNativeFromSource": true
        }
      }]
    ]
  }
}

This disables the precompiled XCFrameworks. However, when trying that out, I still ran into the same errors.

Any idea? Has anyone managed to get 0.4.1 running with Expo 54?

hmm interesting, I didn't know that these headers are stripped out when using precompiled frameworks in Expo. I'll think of a fix for this in Expo. It's just that this is now the best approach on getting the RN version at build time using macros.

@chrispader

Copy link
Copy Markdown
Member

Seems the reason for my problem is using Expo SDK 54, which uses precompiled XCFrameworks for iOS to speed up build times. However, this means that certain header files like ReactNativeVersion.h are not present in a Expo 54 codebase.
A quick fix for this might be to add the following to your app.json:

{
  "expo": {
    "plugins": [
      ["expo-build-properties", {
        "ios": {
          "buildReactNativeFromSource": true
        }
      }]
    ]
  }
}

This disables the precompiled XCFrameworks. However, when trying that out, I still ran into the same errors.
Any idea? Has anyone managed to get 0.4.1 running with Expo 54?

hmm interesting, I didn't know that these headers are stripped out when using precompiled frameworks in Expo. I'll think of a fix for this in Expo. It's just that this is now the best approach on getting the RN version at build time using macros.

@yolpsoftware this is the file I'm referencing: https://github.com/facebook/react-native/blob/main/packages/react-native/ReactCommon/cxxreact/ReactNativeVersion.h

@thejustinwalsh

thejustinwalsh commented Oct 14, 2025

Copy link
Copy Markdown

@chrispader @yolpsoftware With Expo 54 I am able to get this to compile by including the header directly from <cxxreact/ReactNativeVersion.h>.

#if __has_include(<cxxreact/ReactNativeVersion.h>)
#include <cxxreact/ReactNativeVersion.h>

@yolpsoftware

Copy link
Copy Markdown

@thejustinwalsh thank you, but that does not work for me either. I installed the current 0.4.1 version, then went into node_modules/react-native-release-profiler/ios/ReleaseProfiler.mm and replaced the two ReactNativeVersion.h lines with your two lines.

Still getting

- no member named 'enableSamplingProfiler' in 'facebook::hermes::HermesRuntime'
- no type named 'dumpSampledTraceToFile' in 'facebook::hermes::HermesRuntime'
- no member named 'disableSamplingProfiler' in 'facebook::hermes::HermesRuntime'

Also tried

#if __has_include(<ReactCommon/cxxreact/ReactNativeVersion.h>)
#include <ReactCommon/cxxreact/ReactNativeVersion.h>

(since the cxxreact is in the ReactCommon folder), but no luck.

@thejustinwalsh

thejustinwalsh commented Oct 14, 2025

Copy link
Copy Markdown

Moving discussion to #20 as this issue is merged.
👉 #20 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants