Skip to content

Commit 4b5f00e

Browse files
Bartol Karuzacpojer
authored andcommitted
Document how to publish custom React Native version (#675)
* Add section for how to make a git dependency branch (#653) * move publishing a fork to separate page (#653) * updated review comments * link back from building android sources and updated docker link * changed to —force instead of changing .gitignore * Update publishing.md
1 parent e6e3046 commit 4b5f00e

File tree

3 files changed

+84
-13
lines changed

3 files changed

+84
-13
lines changed

docs/building-from-source.md

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Make sure you have the following installed:
1818
3. Android Support Repository >= 28 (for Android Support Library)
1919
4. Android NDK (download links and installation instructions below)
2020

21-
#### Point Gradle to your Android SDK:
21+
#### [Point Gradle to your Android SDK](#gradle-android-sdk):
2222

2323
**Step 1:** Set environment variables through your local shell.
2424

@@ -139,22 +139,14 @@ gradle.projectsLoaded {
139139
}
140140
```
141141

142-
### Building for Maven/Nexus deployment
143-
144-
If you find that you need to push up a locally compiled React Native .aar and related files to a remote Nexus repository, you can.
145-
146-
Start by following the `Point Gradle to your Android SDK` section of this page. Once you do this, assuming you have Gradle configured properly, you can then run the following command from the root of your React Native checkout to build and package all required files:
147-
148-
```
149-
./gradlew ReactAndroid:installArchives
150-
```
151-
152-
This will package everything that would typically be included in the `android` directory of your `node_modules/react-native/` installation in the root directory of your React Native checkout.
153-
154142
### Troubleshooting
155143

156144
Gradle build fails in `ndk-build`. See the section about `local.properties` file above.
157145

158146
## Testing your Changes
159147

160148
If you made changes to React Native and submit a pull request, all tests will run on your pull request automatically. To run the tests locally, see [Testing your Changes](testing.md).
149+
150+
## Making your changes available
151+
152+
See the [Publishing your own version of react native](publishing.md) for several options to make your changes available for your and other app projects.

docs/publishing.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
---
2+
id: publishing-forks
3+
title: Publish your own version of react native
4+
---
5+
6+
TL;DR
7+
---
8+
There is a docker image that helps you build the required Android sources without installing any additional tooling (other than [Docker](https://docs.docker.com/install/), which can be committed to a git branch as a fully functional React Native fork release.
9+
10+
Run this from a fork of the React Native [repo](https://github.com/facebook/react-native).
11+
```
12+
git checkout -d release/my-react-native-release
13+
docker run --rm --name rn-build -v $PWD:/pwd -w /pwd reactnativecommunity/react-native-android /bin/sh -c "./gradlew installArchives"
14+
git add android --force
15+
git commit -a -m 'my react native forked release'
16+
git push
17+
```
18+
19+
Install it in your app project package.json.
20+
```
21+
"dependencies": {
22+
...
23+
"react-native": "myName/react-native#release/my-react-native-release"
24+
}
25+
```
26+
27+
Rationale
28+
---
29+
The recommended approach to working with React Native is to always update to the latest version. No support is provided on older versions and if you run into issues the contributors will always ask you to upgrade to the latest version before even looking at your particular issue. Sometimes, though, you are temporarily stuck on an older React Native version, but you require some changes from newer versions urgently (bugfixes) without having to do a full upgrade right now. This situation should be short lived by definition and once you have the time, the real solution is to upgrade to the latest version.
30+
31+
With this goal of a shortlived fork of React Native in mind, you can publish your own version of React Native. The facebook/react-native repository contains all the dependencies required to be used directly as a git dependency, except for the Android React Native library binary (.aar).
32+
33+
Building
34+
---
35+
36+
This binary needs to become available in your project's `node_modules/react-native/android` folder or directly in your gradle dependency of your Android app. You can achieve this in one of two ways: Git dependency branch, Android binary dependency through Maven.
37+
38+
To build the .aar React Native library, you can follow the steps to [build from source](building-from-source.md) first to install all required tooling. Then to build the actual library, you can run the following in the root of your react-native checkout:
39+
```$bash
40+
./gradlew :ReactAndroid:installArchives --no-daemon
41+
```
42+
43+
If you don't want to
44+
install the required toolchain for building from source, you can use a prebuilt docker image to create a react native binary;
45+
```
46+
docker run --rm --name rn-build -v $PWD:/pwd -w /pwd reactnativecommunity/react-native-android /bin/sh -c "./gradlew installArchives"
47+
```
48+
If you haven't used the Android NDK before or if you have a NDK version not exactly matching the required version for building React Native, this is the recommended approach.
49+
50+
The resulting binary can be made available to app projects in one of the two ways described below.
51+
52+
### Publishing to Maven/Nexus
53+
Upload the binaries from the `android` folder to maven and point your Android app project gradle dependency for React Native to your Maven/Nexus dependency.
54+
55+
### Publishing to a git fork dependency
56+
Instead of uploading to Maven/Nexus, you can add the binaries built in the previous steps to git, by changing the .gitignore and committing the binaries to your forked branch. This allows you to make your fork into a functioning git dependency for React Native app projects.
57+
58+
If you have changes that you want to actually merge to React Native, make them on another branch first and open a PR. To start making your dependency branch, make sure you are on a 'release/my-forked-release' branch, then merge any commits that you need from yourself or others into this branch. This release branch should never be merged into any other branch.
59+
60+
```$bash
61+
# create .aar, then:
62+
git add android --force
63+
git commit -m 'my release commit'
64+
git push
65+
```
66+
67+
Now you can use this branch as a git dependency in your app project, by pointing your package.json dependency to this branch:
68+
69+
```
70+
"dependencies": {
71+
...
72+
"react-native": "my-name/react-native#release/my-forked-release,
73+
...
74+
}
75+
```
76+
77+
No other modifications to your dependencies should be necessary for your native changes to be included in your project.
78+

website/sidebars.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
"contributing",
5858
"maintainers",
5959
"building-from-source",
60+
"publishing-forks",
6061
"testing"
6162
],
6263
"Components": [

0 commit comments

Comments
 (0)