Skip to content

Commit 167dd9d

Browse files
kraenhansenclaude
andauthored
docs: clarify the Android Hermes vendoring steps (#411)
The Android setup has two separate requirements — building React Native from source and pointing it at the vendored Hermes — and the doc ran them together without saying why either is needed. - Split them into their own sections and say up front that this is the manual equivalent of what `pod install` does on Apple platforms. - Note that apps based on react-native-test-app get the dependency substitutions from `react.buildFromSource=true` instead of editing settings.gradle themselves, as apps/test-app does. - Spell out that REACT_NATIVE_OVERRIDE_HERMES_DIR is read from the environment (Gradle cannot set it for its own build), so it has to be exported for every shell — or for the environment Android Studio is launched from — and what goes wrong without it. Also drop the last two references to a "patched" Hermes from the host README, left over from before we adopted Hermes' first-party Node-API. Claude-Session: https://claude.ai/code/session_01HX4imsygeawVtsmoP1sj3F Co-authored-by: Claude <noreply@anthropic.com>
1 parent 7debd88 commit 167dd9d

2 files changed

Lines changed: 38 additions & 4 deletions

File tree

docs/ANDROID.md

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
# Android support
22

3-
## Building Hermes from source
3+
Android needs two things that iOS gets automatically during `pod install`:
4+
React Native has to be built from source, and the build has to be pointed at the
5+
Hermes we vendor. Both are described below.
46

5-
Because we build Hermes from source (a pinned commit carrying its Node-API implementation), we need to build React Native from source too.
7+
## Building React Native from source
8+
9+
Because we build Hermes from source (a pinned commit carrying its Node-API
10+
implementation), we need to build React Native from source too.
611

712
Follow [the React Native documentation on how to build from source](https://reactnative.dev/contributing/how-to-build-from-source#update-your-project-to-build-from-source).
813

@@ -23,6 +28,14 @@ In particular, you will have to edit the `android/settings.gradle` file as follo
2328
> + }
2429
> ```
2530
31+
If your app is based on [`react-native-test-app`](https://github.com/microsoft/react-native-test-app),
32+
you don't need to edit `settings.gradle` yourself: it applies the same
33+
substitutions when `react.buildFromSource=true` is set in
34+
`android/gradle.properties`. That is how the test app in this repository builds —
35+
see [`apps/test-app/android/gradle.properties`](../apps/test-app/android/gradle.properties).
36+
37+
## Vendoring Hermes
38+
2639
To fetch the pinned Hermes, you need to run from your app package:
2740
2841
```
@@ -37,6 +50,27 @@ This can be combined into a single line:
3750
export REACT_NATIVE_OVERRIDE_HERMES_DIR=$(npx react-native-node-api vendor-hermes --silent)
3851
```
3952
53+
React Native reads this as an environment variable, and Gradle cannot set one
54+
for its own build, so it has to be exported in whatever ends up invoking Gradle:
55+
56+
- the terminal you run `./gradlew` or `npx react-native run-android` from, for
57+
every new shell,
58+
- or the environment Android Studio is launched from — starting it from a shell
59+
that has the variable set is the simplest way to get it there.
60+
61+
Re-running the command is cheap: it re-uses the existing clone and just prints
62+
its path. If the variable is missing, the build fails early with a message
63+
repeating the command to run.
64+
65+
Without the override, React Native downloads and builds its own Hermes, which
66+
does not carry the Node-API implementation this package links against — the
67+
build then fails to find `hermes_napi_create_env`.
68+
69+
> [!NOTE]
70+
> On Apple platforms this is automated: the podspec vendors Hermes during
71+
> `pod install` when the variable isn't already set, so there is no manual step
72+
> there.
73+
4074
## Cleaning your React Native build folders
4175
4276
If you've accidentally built your app without the vendored Hermes, you can clean things up by deleting the `ReactAndroid` build folder.

packages/host/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ The plugin rewrites the `require("./addon.node")` (and `require("bindings")("add
4747
### 3. Build your app
4848

4949
- **iOS:** run `pod install` as usual — addons found in your dependencies are linked as part of it. Re-run it whenever you add or remove a dependency shipping an addon.
50-
- **Android:** requires a few extra steps, since React Native has to be built from source against the patched Hermes. See [the Android documentation](https://github.com/callstackincubator/react-native-node-api/blob/main/docs/ANDROID.md).
50+
- **Android:** requires a few extra steps, since React Native has to be built from source against the vendored Hermes. See [the Android documentation](https://github.com/callstackincubator/react-native-node-api/blob/main/docs/ANDROID.md).
5151

5252
## Usage
5353

@@ -79,6 +79,6 @@ This prints every Node-API module it finds in your dependencies and the name it
7979
## Documentation
8080

8181
- [Auto-linking](https://github.com/callstackincubator/react-native-node-api/blob/main/docs/AUTO-LINKING.md) — how prebuilt binaries are discovered, copied and renamed.
82-
- [Android support](https://github.com/callstackincubator/react-native-node-api/blob/main/docs/ANDROID.md) — building React Native from source with the patched Hermes.
82+
- [Android support](https://github.com/callstackincubator/react-native-node-api/blob/main/docs/ANDROID.md) — building React Native from source with the vendored Hermes.
8383
- [Usage](https://github.com/callstackincubator/react-native-node-api/blob/main/docs/USAGE.md) — for library authors wanting to ship a Node-API module.
8484
- [How it works](https://github.com/callstackincubator/react-native-node-api/blob/main/docs/HOW-IT-WORKS.md) — the path from `import` to native code.

0 commit comments

Comments
 (0)