You will need to build React Native from source if you want to work on a new feature/bug fix, try out the latest features which are not released yet, or maintain your own fork with patches that cannot be merged to the core.
Assuming you have the Android SDK installed, run
android to open the Android SDK Manager.
Make sure you have the following installed:
Step 1: Set environment variables through your local shell.
Note: Files may vary based on shell flavor. See below for examples from common shells.
Step 2: Create a
local.properties file in the
android directory of your react-native app with the following contents:
You can find further instructions on the official page.
First, you need to install
react-native from your fork. For example, to install the master branch from the official repo, run the following:
Alternatively, you can clone the repo to your
node_modules directory and run
npm install inside the cloned repo.
gradle-download-task as dependency in
:ReactAndroid project in
android/app/build.gradle to use the
:ReactAndroid project instead of the pre-compiled library, e.g. - replace
compile 'com.facebook.react:react-native:+' with
If you use 3rd-party React Native modules, you need to override their dependencies so that they don't bundle the pre-compiled library. Otherwise you'll get an error while compiling -
Error: more than one library with package name 'com.facebook.react'.
android/app/build.gradle, and add:
From the Welcome screen of Android Studio choose "Import project" and select the
android folder of your app.
You should be able to use the Run button to run your app on a device. Android Studio won't start the packager automatically, you'll need to start it by running
npm start on the command line.
Building from source can take a long time, especially for the first build, as it needs to download ~200 MB of artifacts and compile the native code. Every time you update the
react-native version from your repo, the build directory may get deleted, and all the files are re-downloaded. To avoid this, you might want to change your build directory path by editing the
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.
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:
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.
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 Running Tests.
Gradle build fails in
ndk-build. See the section about
local.properties file above.
Improve this page by sending a pull request!