Skip to content

Commit 6b62848

Browse files
committed
chore: simplify settings.gradle script, extend docs
1 parent 4c0cc1d commit 6b62848

File tree

5 files changed

+60
-2
lines changed

5 files changed

+60
-2
lines changed

apps/test-app/android/settings.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,7 @@ apply(from: {
1919
throw new GradleException("Could not find `react-native-test-app`");
2020
}())
2121
applyTestAppSettings(settings)
22+
23+
// customize the path to match your node_modules location
24+
apply(from: "../../../node_modules/react-native-node-api/android/consumerSettings.gradle")
25+
applyNodeAPISettings(settings)

docs/ANDROID.md

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

3-
## Building Hermes from source
3+
## Android setup
4+
5+
### Step 1: `settings.gradle`
6+
7+
Gradle needs special handling to build React Native from source. In your app's `settings.gradle` please include the below:
8+
9+
```groovy
10+
// customize the path to match your node_modules location
11+
apply(from: "../../../node_modules/react-native-node-api/android/consumerSettings.gradle")
12+
applyNodeAPISettings(settings)
13+
```
14+
15+
### Step 2: script for adjusting environment variables
16+
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
422

523
Because we're using a version of Hermes patched with Node-API support, we need to build React Native from source.
624

25+
Alternatively, if for whatever reason you want to do it manually, you can do so by exporting this environment variable before Gradle invocation:
26+
727
```
8-
export REACT_NATIVE_OVERRIDE_HERMES_DIR=`npx react-native-node-api vendor-hermes --silent`
28+
export REACT_NATIVE_OVERRIDE_HERMES_DIR="$(npx react-native-node-api vendor-hermes --silent)"
929
```
1030

31+
> [!TIP]
32+
> This above automatically done by our script. If you run it from postinstall, there is no need to do this manually.
33+
1134
## Cleaning your React Native build folders
1235

1336
If you've accidentally built your app without Hermes patched, you can clean things up by deleting the `ReactAndroid` build folder.

docs/IOS.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# iOS support
2+
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.

package-lock.json

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import org.gradle.initialization.DefaultSettings
2+
3+
4+
ext.applyNodeAPISettings = { DefaultSettings settings ->
5+
def searchDirectory = rootDir.toPath()
6+
do {
7+
def p = searchDirectory.resolve("node_modules/react-native")
8+
if (p.toFile().exists()) {
9+
println "[RN-NAPI] Found React Native in ${p.toRealPath().toString()}"
10+
11+
includeBuild(p.toRealPath().toString()) {
12+
dependencySubstitution {
13+
substitute(module("com.facebook.react:react-android")).using(project(":packages:react-native:ReactAndroid"))
14+
substitute(module("com.facebook.react:react-native")).using(project(":packages:react-native:ReactAndroid"))
15+
substitute(module("com.facebook.react:hermes-android")).using(project(":packages:react-native:ReactAndroid:hermes-engine"))
16+
substitute(module("com.facebook.react:hermes-engine")).using(project(":packages:react-native:ReactAndroid:hermes-engine"))
17+
}
18+
}
19+
break
20+
}
21+
} while (searchDirectory = searchDirectory.getParent())
22+
}

0 commit comments

Comments
 (0)