-
Notifications
You must be signed in to change notification settings - Fork 24.8k
Building from source
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:
- Android SDK version 28 (compileSdkVersion in
build.gradle
) - SDK build tools version 28.0.3 (buildToolsVersion in
build.gradle
) - Android Support Repository >= 28 (for Android Support Library)
- Android NDK (download links and installation instructions below)
Step 1: Set environment variables through your local shell.
Note: Files may vary based on shell flavor. See below for examples from common shells.
- bash:
.bash_profile
or.bashrc
- zsh:
.zprofile
or.zshrc
- ksh:
.profile
or$ENV
Example:
export ANDROID_SDK=/Users/your_unix_name/android-sdk-macosx
export ANDROID_NDK=/Users/your_unix_name/android-ndk/android-ndk-r17c
Step 2: Create a local.properties
file in the android
directory of your react-native app with the following contents:
Example:
sdk.dir=/Users/your_unix_name/android-sdk-macosx
ndk.dir=/Users/your_unix_name/android-ndk/android-ndk-r17c
- Mac OS (64-bit) - http://dl.google.com/android/repository/android-ndk-r17c-darwin-x86_64.zip
- Linux (64-bit) - http://dl.google.com/android/repository/android-ndk-r17c-linux-x86_64.zip
- Windows (64-bit) - http://dl.google.com/android/repository/android-ndk-r17c-windows-x86_64.zip
- Windows (32-bit) - http://dl.google.com/android/repository/android-ndk-r17c-windows-x86.zip
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:
npm install --save github:facebook/react-native#master
Alternatively, you can clone the repo to your node_modules
directory and run npm install
inside the cloned repo.
Add gradle-download-task
as dependency in android/build.gradle
:
...
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'de.undercouch:gradle-download-task:3.4.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
...
Add the :ReactAndroid
project in android/settings.gradle
:
...
include ':ReactAndroid'
project(':ReactAndroid').projectDir = new File(
rootProject.projectDir, '../node_modules/react-native/ReactAndroid')
...
Modify your android/app/build.gradle
to use the :ReactAndroid
project instead of the pre-compiled library, e.g. - replace implementation 'com.facebook.react:react-native:+'
with implementation project(':ReactAndroid')
:
...
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}'
implementation project(':ReactAndroid')
...
}
...
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'
.
Modify your android/app/build.gradle
, and add:
configurations.all {
exclude group: 'com.facebook.react', module: 'react-native'
}
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 ~/.gradle/init.gradle
file:
gradle.projectsLoaded {
rootProject.allprojects {
buildDir = "/path/to/build/directory/${rootProject.name}/${project.name}"
}
}
Gradle build fails in ndk-build
. See the section about local.properties
file above.
React Native • Contributor Guide • Getting Started • Website
How to Contribute
- How to File an Issue ↗
- Triaging GitHub Issues ↗
- How to Label an Issue ↗
- Managing Pull Requests ↗
- How to Contribute Code ↗
- How to Open a Pull Request ↗
- How to Build from Source ↗
Tests
Releases
More Resources
- Contributor Guide ↗
- Code of Conduct ↗
- Contributor License Agreement ↗
- Discussions and Proposals ↗
- Bots Reference ↗
Documentation