|
1 | 1 | # Android support |
2 | 2 |
|
3 | | -## Android setup |
| 3 | +## Building Hermes from source |
4 | 4 |
|
5 | 5 | ### Step 1: `settings.gradle` |
6 | 6 |
|
7 | | -Gradle needs special handling to build React Native from source. In your app's `settings.gradle` please include the below: |
| 7 | +Gradle needs specific configuration to build React Native from source: dependency substitutions for React Native & Hermes modules, and modifications to default logic in RN build scripts, which is done by setting an environment variable, as described in this section. |
| 8 | + |
| 9 | +In your app's `settings.gradle` please include the below: |
8 | 10 |
|
9 | 11 | ```groovy |
10 | 12 | // customize the path to match your node_modules location |
11 | | -apply(from: "../../../node_modules/react-native-node-api/android/consumerSettings.gradle") |
| 13 | +apply(from: "../../../node_modules/react-native-node-api/android/app-settings.gradle") |
12 | 14 | applyNodeAPISettings(settings) |
13 | 15 | ``` |
14 | 16 |
|
15 | 17 | ### Step 2: script for adjusting environment variables |
16 | 18 |
|
17 | | -To integrate automatic setup of Hermes engine, a special env variable (`REACT_NATIVE_OVERRIDE_HERMES_DIR`) must be set to a proper path. Since Gradle does not really support loading `.env` files, this must be automated by the consumer. We provide the script `react-native-node-api vendor-hermes --silent` which will output a single line, the path to Hermes directory. |
18 | | - |
19 | | -Each time you run Android Studio, make sure this is in place. |
20 | | - |
21 | | -### How it works: building Hermes from source |
| 19 | +> [!IMPORTANT] |
| 20 | +> Each time you run Android Studio or build the Android app from a terminal, make sure the below is in place. |
22 | 21 |
|
23 | | -Because we're using a version of Hermes patched with Node-API support, we need to build React Native from source. |
| 22 | +Because we're using a version of Hermes patched with Node-API support, we need to build React Native from source. A special environment variable (`REACT_NATIVE_OVERRIDE_HERMES_DIR`) must be set to the path of a Hermes engine with Node-API support. Since Gradle does not support loading `.env` files directly, this must be automated by the consumer. We provide the `react-native-node-api vendor-hermes --silent` command, which will download Hermes and output the path to Hermes directory path as its only output. |
24 | 23 |
|
25 | | -Alternatively, if for whatever reason you want to do it manually, you can do so by exporting this environment variable before Gradle invocation: |
| 24 | +You can configure the environment variable using the following command: |
26 | 25 |
|
27 | 26 | ``` |
28 | 27 | export REACT_NATIVE_OVERRIDE_HERMES_DIR="$(npx react-native-node-api vendor-hermes --silent)" |
29 | 28 | ``` |
30 | 29 |
|
31 | | -> [!TIP] |
32 | | -> This above automatically done by our script. If you run it from postinstall, there is no need to do this manually. |
| 30 | +This either needs to be done each time before Gradle / Android Studio invocation, or permanently in a shell init script such as `~/.zshrc` on Zsh (MacOS) or `~/.bashrc` on Bash (Linux). |
33 | 31 |
|
34 | 32 | ## Cleaning your React Native build folders |
35 | 33 |
|
|
0 commit comments