From 17df7296a09b8ee0068f4512752e6e2f3570f9f6 Mon Sep 17 00:00:00 2001 From: ifsnow Date: Wed, 17 Apr 2019 19:02:05 +0900 Subject: [PATCH 1/2] fix: prevent unnecessary actions if build failed --- .../platform-android/src/commands/runAndroid/index.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/platform-android/src/commands/runAndroid/index.js b/packages/platform-android/src/commands/runAndroid/index.js index f11e44e34..ccd0332b1 100644 --- a/packages/platform-android/src/commands/runAndroid/index.js +++ b/packages/platform-android/src/commands/runAndroid/index.js @@ -120,7 +120,10 @@ function runOnSpecificDevice( const devices = adb.getDevices(adbPath); if (devices && devices.length > 0) { if (devices.indexOf(args.deviceId) !== -1) { - buildApk(gradlew); + if (!buildApk(gradlew)) { + return; + } + installAndLaunchOnDevice( args, args.deviceId, @@ -149,9 +152,13 @@ function buildApk(gradlew) { execFileSync(gradlew, ['build', '-x', 'lint'], { stdio: [process.stdin, process.stdout, process.stderr], }); + + return true; } catch (e) { logger.error('Could not build the app, read the error above for details.'); } + + return false; } function tryInstallAppOnDevice(args, adbPath, device) { From aa6a4ebcef25b2020240cfcaf89159e2d406e327 Mon Sep 17 00:00:00 2001 From: ifsnow Date: Thu, 18 Apr 2019 11:27:46 +0900 Subject: [PATCH 2/2] throw CLIError instead of using boolean --- .../src/commands/runAndroid/index.js | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/packages/platform-android/src/commands/runAndroid/index.js b/packages/platform-android/src/commands/runAndroid/index.js index ccd0332b1..e3e37b5ad 100644 --- a/packages/platform-android/src/commands/runAndroid/index.js +++ b/packages/platform-android/src/commands/runAndroid/index.js @@ -22,6 +22,7 @@ import { isPackagerRunning, logger, getDefaultUserTerminal, + CLIError, } from '@react-native-community/cli-tools'; // Verifies this is an Android project @@ -120,10 +121,7 @@ function runOnSpecificDevice( const devices = adb.getDevices(adbPath); if (devices && devices.length > 0) { if (devices.indexOf(args.deviceId) !== -1) { - if (!buildApk(gradlew)) { - return; - } - + buildApk(gradlew); installAndLaunchOnDevice( args, args.deviceId, @@ -152,13 +150,12 @@ function buildApk(gradlew) { execFileSync(gradlew, ['build', '-x', 'lint'], { stdio: [process.stdin, process.stdout, process.stderr], }); - - return true; - } catch (e) { - logger.error('Could not build the app, read the error above for details.'); + } catch (error) { + throw new CLIError( + 'Could not build the app, read the error above for details', + error, + ); } - - return false; } function tryInstallAppOnDevice(args, adbPath, device) {