Skip to content

Commit 9077adf

Browse files
committed
refactor: changes after CR
1 parent c755b10 commit 9077adf

File tree

7 files changed

+18
-23
lines changed

7 files changed

+18
-23
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
2828
See the document on ["how it works"](./docs/HOW-IT-WORKS.md) for a detailed description of what it's like to write native modules using this package.
2929

30+
### Quick start
31+
32+
To get started, first install the dependencies with `npm i` and then build all packages using `npm run build`.
33+
3034
## Packages
3135

3236
This mono-repository hosts the development of a few packages:

apps/test-app/android/settings.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ apply(from: {
2121
applyTestAppSettings(settings)
2222

2323
// customize the path to match your node_modules location
24-
apply(from: "../../../node_modules/react-native-node-api/android/consumerSettings.gradle")
24+
apply(from: "../../../node_modules/react-native-node-api/android/app-settings.gradle")
2525
applyNodeAPISettings(settings)

docs/ANDROID.md

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,33 @@
11
# Android support
22

3-
## Android setup
3+
## Building Hermes from source
44

55
### Step 1: `settings.gradle`
66

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

911
```groovy
1012
// 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")
1214
applyNodeAPISettings(settings)
1315
```
1416

1517
### Step 2: script for adjusting environment variables
1618

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.
2221
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.
2423

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

2726
```
2827
export REACT_NATIVE_OVERRIDE_HERMES_DIR="$(npx react-native-node-api vendor-hermes --silent)"
2928
```
3029

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).
3331

3432
## Cleaning your React Native build folders
3533

docs/IOS.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
11
# iOS support
22

3-
## iOS setup: script for adjusting environment variables
4-
5-
To integrate automatic setup of Hermes engine, a special env variable (`REACT_NATIVE_OVERRIDE_HERMES_DIR`) must be set to a proper path. We provide the script `react-native-node-api vendor-hermes --silent` which will output a single line, the path to Hermes directory.
6-
7-
Each time you run XCode, make sure this is in place.
3+
Because we're using a version of Hermes patched with Node-API support, we need to build React Native from source. Special environment variables (`REACT_NATIVE_OVERRIDE_HERMES_DIR`, `BUILD_FROM_SOURCE`) must be set to the path of a Hermes engine with Node-API support. The podspec of the iOS Pod already includes instrumentation to configure React Native appropriately via [`patch-hermes.rb`](../packages/host/scripts/patch-hermes.rb).

package-lock.json

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
2121
"test": "npm run test --workspace react-native-node-api --workspace cmake-rn --workspace gyp-to-cmake --workspace node-addon-examples",
2222
"bootstrap": "npm run build && npm run bootstrap --workspaces --if-present",
2323
"prerelease": "npm run build && npm run prerelease --workspaces --if-present",
24-
"release": "changeset publish",
25-
"postinstall": "npm run build"
24+
"release": "changeset publish"
2625
},
2726
"author": {
2827
"name": "Callstack",

packages/host/android/consumerSettings.gradle renamed to packages/host/android/app-settings.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ ext.applyNodeAPISettings = { DefaultSettings settings ->
66
do {
77
def p = searchDirectory.resolve("node_modules/react-native")
88
if (p.toFile().exists()) {
9-
println "[RN-NAPI] Found React Native in ${p.toRealPath().toString()}"
9+
println "[Node-API] !!! PATCHING HERMES WITH NODE-API SUPPORT !!! Found React Native in ${p.toRealPath().toString()}"
1010

1111
includeBuild(p.toRealPath().toString()) {
1212
dependencySubstitution {

0 commit comments

Comments
 (0)