10 KiB
id, title, original_id
| id | title | original_id |
|---|---|---|
| version-0.21-android-building-from-source | android-building-from-source | android-building-from-source |
Building React Native from source # | Edit on GitHub |
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.
Prerequisites #
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 23 (compileSdkVersion in
build.gradle) - SDK build tools version 23.0.1 (buildToolsVersion in
build.gradle) - Android Support Repository >= 17 (for Android Support Library)
- Android NDK (download & extraction instructions here)
Point Gradle to your Android SDK: either have $ANDROID_SDK and $ANDROID_NDK defined, or create a local.properties file in the root of your react-native checkout with the following contents:
Example:
Building the source #
1. Installing the fork #
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.
2. Adding gradle dependencies #
Add gradle-download-task as dependency in android/build.gradle:
<span class="token comment" spellcheck="true"> // NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files } ...
3. Adding the :ReactAndroid project #
Add the :ReactAndroid project in android/settings.gradle:
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 compile 'com.facebook.react:react-native:0.16.+' with compile project(':ReactAndroid'):
compile <span class="token function">project<span class="token punctuation">(</span></span><span class="token string">':ReactAndroid'</span><span class="token punctuation">)</span>
<span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>
} ...
4. Making 3rd-party modules use your fork #
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 replace compile project(':react-native-custom-module') with:
Additional notes #
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: