react-native-safe-area-context icon indicating copy to clipboard operation
react-native-safe-area-context copied to clipboard

Support for React Native New Architecture on Android

Open Connerk1 opened this issue 6 months ago • 7 comments

As mentioned in the docs https://appandflow.github.io/react-native-safe-area-context/#new-architecture-support the new architecture support is experimental. My question, is there an official timeline or roadmap for full New Architecture support on Android, or potentially a work around?

We have recently upgraded to react-native-safe-area-context v5.5.2 in a React Native 0.79.2 project and enabled the New Architecture on Android by setting newArchEnabled=true in android/gradle.properties.

To work around this we created a patch (applied via patch-package) that tweaks the library’s CMakeLists.txt, adding missing include directories and adjusting target_link_libraries. This restores the build, but every version bump forces us to re-patch.

Reproduction steps

  1. Start a fresh RN 0.79.2 app (npx react-native@latest init MyApp --version 0.79.2).
  2. Install [email protected].
  3. Enable new architecture: set newArchEnabled=true in android/gradle.properties.
  4. Run react-native run-android.
  5. Observe CMake link errors.

Environment

  • react-native-safe-area-context: 5.5.2
  • React Native: 0.79.2
  • Android Gradle Plugin: 8.4.0
  • CMake: 3.22.1 (default in AGP 8.x)
  • Gradle: 8.7
  • Build flavor: new architecture enabled

Patch sample (for reference)

# react-native-safe-area-context/android/CMakeLists.txt
- target_link_libraries(safeareacontextreactnativemodule ...)
+ target_include_directories(safeareacontextreactnativemodule PRIVATE ${REACT_ANDROID_DIR}/...)
+ target_link_libraries(safeareacontextreactnativemodule
+    ReactAndroid::fabricjni
+    ReactAndroid::react_nativemodule_core
+    ...)  # additional libs required under NewArch

Connerk1 avatar Jul 11 '25 19:07 Connerk1

Hello @Connerk1, could you provide the compilation error that you get? I just tested in our example app on RN 0.79 and it seems to build fine.

janicduplessis avatar Jul 14 '25 14:07 janicduplessis

Hi, when i remove my patch here's the compilation error I get when running yarn react-native run-android with newArchEnabled=true (the build works fine with newArchEnabled=false):

Key Error Summary:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:buildCMakeDebug[arm64-v8a]'.

Key compilation errors:

fatal error: 'ReactCommon/TurboModule.h' file not found
fatal error: 'ReactCommon/JavaTurboModule.h' file not found  
fatal error: 'react/renderer/components/view/ViewProps.h' file not found
fatal error: 'react/renderer/components/view/ViewEventEmitter.h' file not found
fatal error: 'folly/dynamic.h' file not found

All errors occur in files like:
- /node_modules/react-native-safe-area-context/android/build/generated/source/codegen/jni/react/renderer/components/safeareacontext/

More context on these errors if needed:

> Task :app:buildCMakeDebug[arm64-v8a]
C/C++: ninja: Entering directory `/Users/connerkelty/myproject/myproject-mobile/android/app/.cxx/Debug/6y194a3c/arm64-v8a'
C/C++: /Users/connerkelty/Library/Android/sdk/ndk/27.1.12297006/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++ \
  --target=aarch64-none-linux-android24 \
  --sysroot=/Users/connernelty/Library/Android/sdk/ndk/27.1.12297006/toolchains/llvm/prebuilt/darwin-x86_64/sysroot \
  -Dreact_codegen_safeareacontext_EXPORTS \
  -I/Users/connerkelty/myproject/myproject-mobile/node_modules/react-native-safe-area-context/android/src/main/jni/. \
  -I/Users/connerkelty/myproject/myproject-mobile/node_modules/react-native-safe-area-context/android/src/main/jni/../../../../common/cpp \
  -I/Users/connerkelty/myproject/myproject-mobile/node_modules/react-native-safe-area-context/android/src/main/jni/../../../build/generated/source/codegen/jni \
  -I/Users/connerkelty/myproject/myproject-mobile/node_modules/react-native-safe-area-context/android/src/main/jni/../../../build/generated/source/codegen/jni/react/renderer/components/safeareacontext \
  -isystem /Users/connerkelty/.gradle/caches/8.13/transforms/.../jetified-fbjni-0.7.0/prefab/modules/fbjni/include \
  -isystem /Users/connerkelty/.gradle/caches/8.13/transforms/.../jetified-react-android-0.79.2-debug/prefab/modules/jsi/include \
  -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes \
  -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security -fno-limit-debug-info -fPIC -fexceptions -frtti -std=c++20 -Wall -Wpedantic \
  -Wno-gnu-zero-variadic-macro-arguments -Wno-dollar-in-identifier-extension -DLOG_TAG="ReactNative" -DFOLLY_NO_CONFIG=1 \
  -DFOLLY_HAVE_CLOCK_GETTIME=1 -DFOLLY_USE_LIBCPP=1 -DFOLLY_CFG_NO_COROUTINES=1 -DFOLLY_MOBILE=1 -DFOLLY_HAVE_RECVMMSG=1 \
  -DFOLLY_HAVE_PTHREAD=1 -DFOLLY_HAVE_XSI_STRERROR_R=1 \
  -MD -MT safeareacontext_autolinked_build/CMakeFiles/react_codegen_safeareacontext.dir/.../safeareacontextJSI-generated.cpp.o \
  -MF safeareacontext_autolinked_build/CMakeFiles/react_codegen_safeareacontext.dir/.../safeareacontextJSI-generated.cpp.o.d \
  -o safeareacontext_autolinked_build/CMakeFiles/react_codegen_safeareacontext.dir/.../safeareacontextJSI-generated.cpp.o \
  -c /Users/connerkelty/myproject/myproject-mobile/node_modules/react-native-safe-area-context/android/build/generated/source/codegen/jni/react/renderer/components/safeareacontext/safeareacontextJSI-generated.cpp

C/C++: In file included from /Users/connerkelty/.../safeareacontextJSI-generated.cpp:10:
C/C++: /Users/connerkelty/.../safeareacontextJSI.h:12:10: fatal error: 'ReactCommon/TurboModule.h' file not found
   12 | #include <ReactCommon/TurboModule.h>
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~

And here’s the snippet around the ViewEventEmitter.h failure:

C/C++: ninja: build stopped: subcommand failed.
C/C++: [2/42] Building CXX object safeareacontext_autolinked_build/.../ComponentDescriptors.cpp.o
C/C++: /Users/connerkelty/.../clang++ [same -I flags as above] \
  -MD -MT safeareacontext_autolinked_build/.../ComponentDescriptors.cpp.o \
  -MF safeareacontext_autolinked_build/.../ComponentDescriptors.cpp.o.d \
  -o safeareacontext_autolinked_build/.../ComponentDescriptors.cpp.o \
  -c /Users/connerkelty/.../ComponentDescriptors.cpp

C/C++: In file included from /Users/connerkelty/.../ComponentDescriptors.cpp:11:
C/C++: In file included from /Users/connerkelty/.../ShadowNodes.h:13:
C/C++: /Users/connerkelty/.../EventEmitters.h:12:10: fatal error: 'react/renderer/components/view/ViewEventEmitter.h' file not found
   12 | #include <react/renderer/components/view/ViewEventEmitter.h>
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Connerk1 avatar Jul 14 '25 17:07 Connerk1

same problem, finding for resolution. React Native: 0.80.1 react-native-safe-area-context: 5.5.2

In file included from /Users/test/node_modules/react-native-screens/common/cpp/react/renderer/components/rnscreens/RNSFullWindowOverlayShadowNode.cpp:1: /Users/test/node_modules/react-native-screens/common/cpp/react/renderer/components/rnscreens/RNSFullWindowOverlayShadowNode.h:4:10: fatal error: 'react/renderer/components/rnscreens/EventEmitters.h' file not found 4 | #include <react/renderer/components/rnscreens/EventEmitters.h> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1 error generated.

In file included from /Users/test/node_modules/react-native-safe-area-context/common/cpp/react/renderer/components/safeareacontext/RNCSafeAreaViewState.cpp:1: /Users/test/node_modules/react-native-safe-area-context/common/cpp/react/renderer/components/safeareacontext/RNCSafeAreaViewState.h:3:10: fatal error: 'react/renderer/components/safeareacontext/Props.h' file not found 3 | #include <react/renderer/components/safeareacontext/Props.h> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1 error generated.

In file included from /Users/test/node_modules/react-native-safe-area-context/android/src/main/jni/../../../../common/cpp/react/renderer/components/safeareacontext/RNCSafeAreaViewComponentDescriptor.h:3: /Users/test/node_modules/react-native-safe-area-context/android/src/main/jni/../../../../common/cpp/react/renderer/components/safeareacontext/RNCSafeAreaViewShadowNode.h:4:10: fatal error: 'react/renderer/components/safeareacontext/EventEmitters.h' file not found 4 | #include <react/renderer/components/safeareacontext/EventEmitters.h> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1 error generated.

poet-CN avatar Jul 15 '25 06:07 poet-CN

if you get react/renderer/components/safeareacontext/EventEmitters.h' file not found 4 or similar errors on version 5.x.x, that means one of your libraries depend on version 4.x.x or something like that.

find out which libraries use this library with this command; grep -r "react-native-safe-area-context" node_modules/

you most likely need to upgrade that library.

absolutezero13 avatar Jul 26 '25 18:07 absolutezero13

I ran into the same issue, and it turned out to be caused by the Gradle JDK setting in Android Studio > Build, Execution, Deployment > Build Tools > Gradle > Gradle Projects. My setup was using JDK 21, but it needs to be set to JDK 17.

Hope it helps!

same problem, finding for resolution. React Native: 0.80.1 react-native-safe-area-context: 5.5.2

In file included from /Users/test/node_modules/react-native-screens/common/cpp/react/renderer/components/rnscreens/RNSFullWindowOverlayShadowNode.cpp:1: /Users/test/node_modules/react-native-screens/common/cpp/react/renderer/components/rnscreens/RNSFullWindowOverlayShadowNode.h:4:10: fatal error: 'react/renderer/components/rnscreens/EventEmitters.h' file not found 4 | #include <react/renderer/components/rnscreens/EventEmitters.h> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1 error generated.

In file included from /Users/test/node_modules/react-native-safe-area-context/common/cpp/react/renderer/components/safeareacontext/RNCSafeAreaViewState.cpp:1: /Users/test/node_modules/react-native-safe-area-context/common/cpp/react/renderer/components/safeareacontext/RNCSafeAreaViewState.h:3:10: fatal error: 'react/renderer/components/safeareacontext/Props.h' file not found 3 | #include <react/renderer/components/safeareacontext/Props.h> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1 error generated.

In file included from /Users/test/node_modules/react-native-safe-area-context/android/src/main/jni/../../../../common/cpp/react/renderer/components/safeareacontext/RNCSafeAreaViewComponentDescriptor.h:3: /Users/test/node_modules/react-native-safe-area-context/android/src/main/jni/../../../../common/cpp/react/renderer/components/safeareacontext/RNCSafeAreaViewShadowNode.h:4:10: fatal error: 'react/renderer/components/safeareacontext/EventEmitters.h' file not found 4 | #include <react/renderer/components/safeareacontext/EventEmitters.h> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1 error generated.

ihor-zhvanko avatar Aug 10 '25 11:08 ihor-zhvanko

I ran into the same issue, and it turned out to be caused by the Gradle JDK setting in Android Studio > Build, Execution, Deployment > Build Tools > Gradle > Gradle Projects. My setup was using JDK 21, but it needs to be set to JDK 17.

Hope it helps!

I was using JDK 21.0.5 and changed it to JDK 17.0.14. Unfortunately this didn't resolve my issue, still getting the same errors as before.

Connerk1 avatar Aug 15 '25 17:08 Connerk1

if you get react/renderer/components/safeareacontext/EventEmitters.h' file not found 4 or similar errors on version 5.x.x, that means one of your libraries depend on version 4.x.x or something like that.

find out which libraries use this library with this command; grep -r "react-native-safe-area-context" node_modules/

you most likely need to upgrade that library.

I performed the version conflict fix:

To fix this:

  • Added yarn resolution to force single version:
"resolutions": {
  "react-native-safe-area-context": "5.5.2"
}
  • Verified all packages now use 5.5.2 using yarn why react-native-safe-area-context
├─ myProject@workspace:.
│  └─ react-native-safe-area-context@npm:5.5.2 [4bda5] (via npm:5.5.2 [4bda5])
│
└─ react-native-calendars@npm:1.1313.0
   └─ react-native-safe-area-context@npm:5.5.2 [6180c] (via npm:5.5.2 [6180c])

However i'm still getting the same CMake linking errors (EventEmitters.h file not found, etc.) even with unified versions. The version mismatch fix didn't resolve the underlying New Architecture compatibility issue on Android.

Connerk1 avatar Aug 15 '25 18:08 Connerk1