Skip to content

Initialize glog from rninstance on Android - #59861

Open
kraenhansen wants to merge 1 commit into
react:mainfrom
kraenhansen:fix/android-glog-init-rninstance
Open

kraenhansen wants to merge 1 commit into
react:mainfrom
kraenhansen:fix/android-glog-init-rninstance

Conversation

@kraenhansen

Copy link
Copy Markdown
Contributor

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, 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:

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

reactnativejni, which initializes glog, is only loaded lazily on the
New Architecture, so glog output during startup never reached logcat.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@meta-cla meta-cla 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 Nov 8, 2026
@kraenhansen
kraenhansen marked this pull request as ready for review November 8, 2026 10:23
@facebook-github-tools facebook-github-tools Bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Nov 8, 2026

This branch has not been deployed

No deployments
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. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant