From 2bf8f67abf7ba050a54444cdc2f82d25fc927438 Mon Sep 17 00:00:00 2001 From: Mattia Barbon Date: Fri, 11 Aug 2017 22:02:47 +0200 Subject: [PATCH] Fix run-android behaviour when using both --deviceId and --variant Use the correct assemble target (avoids building all targets). Install the correct APK for the requested variant type. Test on a newly-built project, cleaning the android build between tests: # builds and installs app-debug.apk $ rm -rf android/app/build $ react-native run-android --deviceId # builds and installs app-release.apk $ rm -rf android/app/buil $ react-native run-android --deviceId --variant release # builds and installs app-debug.apk $ rm -rf android/app/buil $ react-native run-android --deviceId --variant debug --- local-cli/runAndroid/runAndroid.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/local-cli/runAndroid/runAndroid.js b/local-cli/runAndroid/runAndroid.js index a2626cd9b3f7bf..1275baf231afaf 100644 --- a/local-cli/runAndroid/runAndroid.js +++ b/local-cli/runAndroid/runAndroid.js @@ -118,7 +118,7 @@ function runOnSpecificDevice(args, gradlew, packageNameWithSuffix, packageName, let devices = adb.getDevices(); if (devices && devices.length > 0) { if (devices.indexOf(args.deviceId) !== -1) { - buildApk(gradlew); + buildApk(args, gradlew); installAndLaunchOnDevice(args, args.deviceId, packageNameWithSuffix, packageName, adbPath); } else { console.log('Could not find device with the id: "' + args.deviceId + '".'); @@ -130,12 +130,23 @@ function runOnSpecificDevice(args, gradlew, packageNameWithSuffix, packageName, } } -function buildApk(gradlew) { +function buildApk(args, gradlew) { try { console.log(chalk.bold('Building the app...')); + var gradleArgs = []; + if (args.variant) { + gradleArgs.push('assemble' + + args.variant[0].toUpperCase() + args.variant.slice(1) + ); + } else { + gradleArgs.push('assembleDebug'); + } + // using '-x lint' in order to ignore linting errors while building the apk - child_process.execFileSync(gradlew, ['build', '-x', 'lint'], { + gradleArgs.push('-x', 'lint'); + + child_process.execFileSync(gradlew, gradleArgs, { stdio: [process.stdin, process.stdout, process.stderr], }); } catch (e) {