From 1cc7ef072ebe8bdd434137f0d3c953620e630969 Mon Sep 17 00:00:00 2001 From: Alon Burg Date: Thu, 23 Jun 2016 06:43:12 -0700 Subject: [PATCH] =?UTF-8?q?Fixes=208309:=20Automatically=20run=20`adb=20re?= =?UTF-8?q?verse=20tcp:8081=20tcp:8081`=20when=20st=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: in `runAndroid.js` I renamed the `buildAndRun()` into `run()` and added a call to `runAdbReverse` Closes https://github.com/facebook/react-native/pull/8345 Differential Revision: D3475782 Pulled By: mkonicek fbshipit-source-id: 6f2c5a3e6d61cbeec914175686d2a7909d22a957 --- local-cli/runAndroid/runAndroid.js | 36 +++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/local-cli/runAndroid/runAndroid.js b/local-cli/runAndroid/runAndroid.js index 56b534d92..26a49cff2 100644 --- a/local-cli/runAndroid/runAndroid.js +++ b/local-cli/runAndroid/runAndroid.js @@ -62,7 +62,7 @@ function _runAndroid(argv, config, resolve, reject) { console.log(chalk.bold(`Starting JS server...`)); startServerInNewWindow(); } - buildAndRun(args, reject); + run(args, reject); })); } @@ -71,10 +71,38 @@ function checkAndroid(args) { return fs.existsSync(path.join(args.root, 'android/gradlew')); } +function getAdbPath() { + return process.env.ANDROID_HOME + ? process.env.ANDROID_HOME + '/platform-tools/adb' + : 'adb'; +} + +// Runs ADB reverse tcp:8081 tcp:8081 to allow loading the jsbundle from the packager +function tryRunAdbReverse() { + try { + const adbPath = getAdbPath(); + const adbArgs = ['reverse', 'tcp:8081', 'tcp:8081']; + + console.log(chalk.bold( + `Running ${adbPath} ${adbArgs.join(' ')}` + )); + + child_process.execFileSync(adbPath, adbArgs, { + stdio: [process.stdin, process.stdout, process.stderr], + }); + } catch(e) { + console.log(chalk.yellow( + `Could not run adb reverse: ${e.message}` + )); + } +} + // Builds the app and runs it on a connected emulator / device. -function buildAndRun(args, reject) { +function run(args, reject) { process.chdir(path.join(args.root, 'android')); try { + tryRunAdbReverse(); + const cmd = process.platform.startsWith('win') ? 'gradlew.bat' : './gradlew'; @@ -126,9 +154,7 @@ function buildAndRun(args, reject) { 'utf8' ).match(/package="(.+?)"/)[1]; - const adbPath = process.env.ANDROID_HOME - ? process.env.ANDROID_HOME + '/platform-tools/adb' - : 'adb'; + const adbPath = getAdbPath(); const devices = adb.getDevices();