Repository navigation
Commit 1593375
authored
Initialize glog from rninstance on Android
## 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: #598611 parent cea863e commit 1593375
2 files changed
Lines changed: 9 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| 34 | + | |
34 | 35 | | |
35 | 36 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
15 | 20 | | |
16 | 21 | | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
17 | 25 | | |
18 | 26 | | |
19 | 27 | | |
| |||
0 commit comments