Fixes 8309: Automatically run `adb reverse tcp:8081 tcp:8081` when st…
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
This commit is contained in:
parent
a2c1170da5
commit
1cc7ef072e
|
@ -62,7 +62,7 @@ function _runAndroid(argv, config, resolve, reject) {
|
||||||
console.log(chalk.bold(`Starting JS server...`));
|
console.log(chalk.bold(`Starting JS server...`));
|
||||||
startServerInNewWindow();
|
startServerInNewWindow();
|
||||||
}
|
}
|
||||||
buildAndRun(args, reject);
|
run(args, reject);
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,10 +71,38 @@ function checkAndroid(args) {
|
||||||
return fs.existsSync(path.join(args.root, 'android/gradlew'));
|
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.
|
// 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'));
|
process.chdir(path.join(args.root, 'android'));
|
||||||
try {
|
try {
|
||||||
|
tryRunAdbReverse();
|
||||||
|
|
||||||
const cmd = process.platform.startsWith('win')
|
const cmd = process.platform.startsWith('win')
|
||||||
? 'gradlew.bat'
|
? 'gradlew.bat'
|
||||||
: './gradlew';
|
: './gradlew';
|
||||||
|
@ -126,9 +154,7 @@ function buildAndRun(args, reject) {
|
||||||
'utf8'
|
'utf8'
|
||||||
).match(/package="(.+?)"/)[1];
|
).match(/package="(.+?)"/)[1];
|
||||||
|
|
||||||
const adbPath = process.env.ANDROID_HOME
|
const adbPath = getAdbPath();
|
||||||
? process.env.ANDROID_HOME + '/platform-tools/adb'
|
|
||||||
: 'adb';
|
|
||||||
|
|
||||||
const devices = adb.getDevices();
|
const devices = adb.getDevices();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue