Skip to content
Browse files
Add the configuration option to the run-android command
Currently, to generate a `Release` build in `Android` it is required to get into the `android` directory and run the `react native bundle`with a lot of options and after that run the `gradle` to assemble or install the application with the build type `Release`.

This PR improves the process adding that feature to the `React Native CLI`.

To generate a release build is only required to use the parameter `--configuration` with the value `Release`.


To generate a release build:
react-native run-android --configuration release

To generate a release build for the product flavors staging:
react-native run-android --configuration release --flavor staging

To generate a debug build:
react-native run-android

To generate a debug build for the product flavors staging:
react-native run-android --flavor staging

This PR also removes the option `--install-debug` from the `react-native run-android` because that is always the default value,
Closes #10867

Differential Revision: D4167203

Pulled By: cpojer

fbshipit-source-id: c5ac07f81feeeea00ee0e8b059b46ef0d258a1a6
  • Loading branch information
SandroMachado authored and Facebook Github Bot committed Nov 14, 2016
1 parent 39cf29c commit 2a2d3c6e5a54c553a5c8a9932d8204463e7bbb49
Showing with 33 additions and 13 deletions.
  1. +4 −0 docs/
  2. +29 −13 local-cli/runAndroid/runAndroid.js
@@ -148,6 +148,10 @@ $ react-native run-android

> If you get a "bridge configuration isn't available" error, see [Using adb reverse](#using-adb-reverse).
> Hint
> You can also use the `React Native CLI` to generate and run a `Release` build (e.g. `react-native run-android --configuration Release`).
<block class="mac windows linux android ios" />

## Connecting to the development server
@@ -77,14 +77,9 @@ function tryRunAdbReverse(device) {

// Builds the app and runs it on a connected emulator / device.
function buildAndRun(args) {
process.chdir(path.join(args.root, 'android'));
try {
adb.getDevices().map((device) => tryRunAdbReverse(device));

const cmd = process.platform.startsWith('win')
? 'gradlew.bat'
: './gradlew';

const gradleArgs = [];
if (args.variant) {
gradleArgs.push('install' +
@@ -98,13 +93,33 @@ function buildAndRun(args) {
args.flavor[0].toUpperCase() + args.flavor.slice(1)
} else {

if (args.installDebug) {
// Append the build type to the current gradle install configuration. By default it will generate `installDebug`.
gradleArgs[0] = gradleArgs[0] + args.configuration[0].toUpperCase() + args.configuration.slice(1);

// Get the Android project directory.
const androidProjectDir = path.join(args.root, 'android');

if (args.configuration.toUpperCase() === 'RELEASE') {
`Generating the bundle for the release build...`

child_process.execSync(`react-native bundle --platform android --dev false --entry-file --bundle-output ${androidProjectDir}/app/src/main/assets/ --assets-dest ${androidProjectDir}/app/src/main/res/`, {
stdio: [process.stdin, process.stdout, process.stderr]

// Change to the Android directory.

// Get the gradle binary for the current platform.
const cmd = process.platform.startsWith('win')
? 'gradlew.bat'
: './gradlew';

`Building and installing the app on the device (cd android && ${cmd} ${gradleArgs.join(' ')}...`
@@ -116,9 +131,8 @@ function buildAndRun(args) {
'Could not install the app on the device, read the error above for details.\n' +
'Make sure you have an Android emulator running or a device connected and have\n' +
'set up your Android development environment.\n' +
'Go to\n' +
'and check the Android tab for setup instructions.'
'set up your Android development environment:\n' +
// stderr is automatically piped from the gradle process, so the user
// should see the error already, there is no need to do
@@ -206,14 +220,16 @@ module.exports = {
description: 'builds your app and starts it on a connected Android emulator or device',
func: runAndroid,
options: [{
command: '--install-debug',
}, {
command: '--root [string]',
description: 'Override the root directory for the android build (which contains the android directory)',
default: '',
}, {
command: '--flavor [string]',
description: '--flavor has been deprecated. Use --variant instead',
}, {
command: '--configuration [string]',
description: 'You can use `Release` or `Debug`. This creates a build based on the selected configuration. If you want to use the `Release` configuration make sure you have the `signingConfig` configured at `app/build.gradle`.',
default: 'Debug'
}, {
command: '--variant [string]',

0 comments on commit 2a2d3c6

Please sign in to comment.