Sometimes, a situation arises when you might want to update the react-native Android source code without upgrading react-native itself. For example, there's a new bug on Android 12 where the application crashes due to some bug with the animation queue. The potential fix is available on the
main (unreleased) branch, but your app version is a few patches behind. Another situation is when you simply can't upgrade your react-native version yet, but need a fix from future version. In these cases, you can use this approach to "patch" your Android source files and build new .aar binary and use that for your app.
The official steps to build from source are provided by react-native and you can find them here.
The guid is fairly generic and redundant in some cases if you already have a sufficient react-native development environment setup. The steps below describe what has "worked for me" and they may or may not apply to everyone.
1 - Fork React-Native And Clone
Go to Github and fork react-native. Pull the forked code down to your system.
Note: The official instructions tell you to clone react-native into your project's
node_modules. Don't do this. Just pull it down into your favorite development directory.
2 - Checkout the Correct Commit
If you are following this guide, you are most likely trying to patch react-native Android source files at a specific older version. The easiest way to do this is to checkout the commit specified in the respective version's git tag.
3 - Install Dependencies
4 - Configure the SDK
You will need the version of the SDk specifice in the
compileSdkVersion. You can install it via Android Studio.
5 - Configure the NDK
ANDROID_NDK_VERSION key, for the version needed. This can be installed from Android Studio as well.
Note: The official docs provide links to NDK archives. Installing through Android Studio is probably easer. One caveat is that I didn't find arm architecture NDKs in Android Studio. It's not a big deal though to use those since you won't do this often.
6 - Configure Paths
local.properties file in the root. This file is gitignored and should be kept as so.
Your SDK path is in your Library files (if installed through Android Studio).Your NDK path is inside the SDK path. This is what mine looks like:
Note: The official guides also have you setup shell paths with the same values. Not sure if this is needed. It wasn't for me.
7 - Make the Necessary Changes
Now, you can make any changes in the
8 - Build
Run the following command in the root:
arch -x86_64 ./gradlew :ReactAndroid:installArchives --no-daemon
The first time you run this, it'll take some time. It will also report any syntax/type errors. It will also report any configuration errors.
Note: If you installed an arm compatible NDK, omit the
arch -x86_64from the command
9 - Commit and Push
.gitignore, remove the line which ignores the
/android/ directory. We'll want to commit this build output from step 7. Commit and push your fork.
10 - Update Project's React-Native
Now that you have build and pushed your changes, you can reference that in your application's
Note: You'll most likely need to delete/re-install your node_modules as well as run