Skip to content

Decouple NativeMap and NativeArray from reactnativejni - #50437

Closed
cortinico wants to merge 1 commit into
react:mainfrom
cortinico:export-D71635967
Closed

cortinico wants to merge 1 commit into
react:mainfrom
cortinico:export-D71635967

Conversation

@cortinico

Copy link
Copy Markdown
Contributor

Summary:
Currently we do have NativeArray, NativeMap being tightly coupled with the old arch (i.e. everything inside libreactnativejni.so).
Those classes however are primitives used also by the New Arch and they should be accessible even without the bridge infra.

I've noticed this dependency while working on the Legacy Arch warnings.

Here I'm refactoring those primitives to live in a separate libreactnativejni_common module that can be loaded indipendently.

Changelog:
[Internal] [Changed] - Decouple NativeMap and NativeArray from reactnativejni

Differential Revision: D71635967

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Apr 1, 2025
@facebook-github-bot

Copy link
Copy Markdown
Contributor

This pull request was exported from Phabricator. Differential Revision: D71635967

@facebook-github-bot

Copy link
Copy Markdown
Contributor

This pull request was exported from Phabricator. Differential Revision: D71635967

@facebook-github-bot

Copy link
Copy Markdown
Contributor

This pull request was exported from Phabricator. Differential Revision: D71635967

Summary:
Pull Request resolved: react#50437

Currently we do have `NativeArray`, `NativeMap` being tightly coupled with the old arch (i.e. everything inside `libreactnativejni.so`).
Those classes however are primitives used also by the New Arch and they should be accessible even without the bridge infra.

I've noticed this dependency while working on the Legacy Arch warnings.

Here I'm refactoring those primitives to live in a separate `libreactnativejni_common` module that can be loaded indipendently.

Changelog:
[Internal] [Changed] - Decouple NativeMap and NativeArray from `reactnativejni`

Reviewed By: javache, mdvacca

Differential Revision: D71635967
@facebook-github-bot

Copy link
Copy Markdown
Contributor

This pull request was exported from Phabricator. Differential Revision: D71635967

@facebook-github-bot facebook-github-bot added the Merged This PR has been merged. label Apr 3, 2025
@facebook-github-bot

Copy link
Copy Markdown
Contributor

This pull request has been merged in 1786912.

@react-native-bot

Copy link
Copy Markdown
Collaborator

This pull request was successfully merged by @cortinico in 1786912

When will my fix make it into a release? | How to file a pick request?

meta-codesync Bot pushed a commit that referenced this pull request Nov 10, 2026
## Summary:

Part of #59728. Context in #59729 (comment) (problem 1).

glog's logcat sink is installed in the `JNI_OnLoad` of `reactnativejni`. Since #50437, the New Architecture loads that library lazily: on the first transform prop or network inspector use, and on `main` also on the first touch event. Until then, glog writes only to stderr, so warnings and fatal errors logged during startup never reach logcat. Since Android 7.0, `liblog` sets the tombstone's abort message from fatal log writes, so those fatal errors also crash with a bare `SIGABRT`.

This calls `gloginit::initialize()` from `rninstance`'s `JNI_OnLoad`. `ReactInstance` loads `rninstance` before the runtime, Fabric and TurboModules are created. `gloginit::initialize()` runs once per process, so the call in `reactnativejni` stays for the legacy architecture.

## Changelog:

[ANDROID] [FIXED] - Send glog output during startup to logcat on the New Architecture

## Test Plan:

Tested with [rn-hermes-fatal-handler-repro](https://github.com/kraenhansen/rn-hermes-fatal-handler-repro), which triggers a Hermes fatal error with the reason `Max heap size was exceeded`. I cherry-picked this commit onto 0.88.1, built `./gradlew :packages:react-native:ReactAndroid:assembleRelease`, swapped the arm64 libraries into the reproducer's stock-template APK, and ran it 3 times per build on an arm64 API 37 emulator. All runs were consistent.

| Build | Crash | glog warnings in logcat | Fatal reason in logcat | Abort message in tombstone |
| --- | --- | --- | --- | --- |
| 0.88.1 | `SIGSEGV` | No | No | No |
| 0.88.1 + this PR | `SIGSEGV` | Yes | No | No |
| 0.88.1 + #59729 | `SIGABRT` | No | No | No |
| 0.88.1 + #59729 + this PR | `SIGABRT` | Yes | Yes | Yes |

With this PR and #59729:

```text
W ReactNativeJNI: Codegen component descriptors were not configured from JNI_OnLoad
W ReactNativeJNI: ReactInstance: evaluateJavaScript() with JS bundle
F ReactNativeJNI: OOM: error_code(value = 1, category = vm_allocate_category, message = Max heap size was exceeded)
F DEBUG   : Abort message: 'OOM: error_code(value = 1, category = vm_allocate_category, message = Max heap size was exceeded)'
```

Nothing was logged twice, including with a transform on the root view, where `reactnativejni` also loads. I didn't run this on API levels below 37.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Differential Revision: D130915975

Pull Request resolved: #59861
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported Merged This PR has been merged. p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants