-
Notifications
You must be signed in to change notification settings - Fork 7
chore: better gradle setup #188
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 5 commits
511e61a
9f3ed85
4c0cc1d
6b62848
c755b10
9077adf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| '@react-native-node-api/test-app': patch | ||
| 'react-native-node-api': patch | ||
| --- | ||
|
|
||
| Improvements to setup scripts, updated docs |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 22 |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,13 +1,36 @@ | ||||||
| # Android support | ||||||
|
|
||||||
| ## Building Hermes from source | ||||||
| ## Android setup | ||||||
|
artus9033 marked this conversation as resolved.
Outdated
|
||||||
|
|
||||||
| ### Step 1: `settings.gradle` | ||||||
|
|
||||||
| Gradle needs special handling to build React Native from source. In your app's `settings.gradle` please include the below: | ||||||
|
artus9033 marked this conversation as resolved.
Outdated
|
||||||
|
|
||||||
| ```groovy | ||||||
| // customize the path to match your node_modules location | ||||||
| apply(from: "../../../node_modules/react-native-node-api/android/consumerSettings.gradle") | ||||||
|
artus9033 marked this conversation as resolved.
Outdated
|
||||||
| applyNodeAPISettings(settings) | ||||||
| ``` | ||||||
|
|
||||||
| ### Step 2: script for adjusting environment variables | ||||||
|
|
||||||
| 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. | ||||||
|
artus9033 marked this conversation as resolved.
Outdated
|
||||||
|
|
||||||
| Each time you run Android Studio, make sure this is in place. | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd only change 'start' to 'build' - applied 👍 |
||||||
|
|
||||||
| ### How it works: building Hermes from source | ||||||
|
|
||||||
| Because we're using a version of Hermes patched with Node-API support, we need to build React Native from source. | ||||||
|
artus9033 marked this conversation as resolved.
Outdated
|
||||||
|
|
||||||
| Alternatively, if for whatever reason you want to do it manually, you can do so by exporting this environment variable before Gradle invocation: | ||||||
|
artus9033 marked this conversation as resolved.
Outdated
|
||||||
|
|
||||||
| ``` | ||||||
| export REACT_NATIVE_OVERRIDE_HERMES_DIR=`npx react-native-node-api vendor-hermes --silent` | ||||||
| export REACT_NATIVE_OVERRIDE_HERMES_DIR="$(npx react-native-node-api vendor-hermes --silent)" | ||||||
|
artus9033 marked this conversation as resolved.
|
||||||
| ``` | ||||||
|
|
||||||
| > [!TIP] | ||||||
| > This above automatically done by our script. If you run it from postinstall, there is no need to do this manually. | ||||||
|
|
||||||
|
artus9033 marked this conversation as resolved.
Outdated
|
||||||
| ## Cleaning your React Native build folders | ||||||
|
|
||||||
| If you've accidentally built your app without Hermes patched, you can clean things up by deleting the `ReactAndroid` build folder. | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| # iOS support | ||
|
|
||
| ## iOS setup: script for adjusting environment variables | ||
|
|
||
| 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. | ||
|
|
||
| Each time you run XCode, make sure this is in place. | ||
|
artus9033 marked this conversation as resolved.
Outdated
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import org.gradle.initialization.DefaultSettings | ||
|
|
||
|
|
||
| ext.applyNodeAPISettings = { DefaultSettings settings -> | ||
| def searchDirectory = rootDir.toPath() | ||
| do { | ||
| def p = searchDirectory.resolve("node_modules/react-native") | ||
| if (p.toFile().exists()) { | ||
| println "[RN-NAPI] Found React Native in ${p.toRealPath().toString()}" | ||
|
artus9033 marked this conversation as resolved.
Outdated
|
||
|
|
||
| includeBuild(p.toRealPath().toString()) { | ||
| dependencySubstitution { | ||
| substitute(module("com.facebook.react:react-android")).using(project(":packages:react-native:ReactAndroid")) | ||
| substitute(module("com.facebook.react:react-native")).using(project(":packages:react-native:ReactAndroid")) | ||
| substitute(module("com.facebook.react:hermes-android")).using(project(":packages:react-native:ReactAndroid:hermes-engine")) | ||
| substitute(module("com.facebook.react:hermes-engine")).using(project(":packages:react-native:ReactAndroid:hermes-engine")) | ||
| } | ||
| } | ||
| break | ||
| } | ||
| } while (searchDirectory = searchDirectory.getParent()) | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder now ... how this ever worked 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh - I get it now.
The React Native Test App doesn't need this, because of https://github.com/microsoft/react-native-test-app/blob/d06a4ea4abd4dc31231b1c28c253873ce7f80215/test-app.gradle#L55-L65 and
react-native-node-api/apps/test-app/android/gradle.properties
Line 47 in acf1a7c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, that's already set up thanks to RNTA's scripts - I wasn't aware that you had it configured from my talk to @paradowstack before I jumped into the scripts. Do you think we should leave it there / maybe commented, as a reference sample, additionally to the MD docs? I think some may be concerned that the sample app does not contain this configuration if they browse its source for reference.