add --port options to run-android, defaults to 8081

Summary: Closes https://github.com/facebook/react-native/pull/15316

Differential Revision: D5582599

Pulled By: javache

fbshipit-source-id: 575e0540965792a25e6cc572cff103da2c65a262
This commit is contained in:
Chris Trinh 2017-08-08 06:41:14 -07:00 committed by Facebook Github Bot
parent 66a788fd99
commit 898790d88a

View File

@ -66,10 +66,10 @@ function getAdbPath() {
} }
// Runs ADB reverse tcp:8081 tcp:8081 to allow loading the jsbundle from the packager // Runs ADB reverse tcp:8081 tcp:8081 to allow loading the jsbundle from the packager
function tryRunAdbReverse(device) { function tryRunAdbReverse(packagerPort, device) {
try { try {
const adbPath = getAdbPath(); const adbPath = getAdbPath();
const adbArgs = ['reverse', 'tcp:8081', 'tcp:8081']; const adbArgs = ['reverse', `tcp:${packagerPort}`, `tcp:${packagerPort}`];
// If a device is specified then tell adb to use it // If a device is specified then tell adb to use it
if (device) { if (device) {
@ -177,7 +177,7 @@ function tryLaunchAppOnDevice(device, packageNameWithSuffix, packageName, adbPat
} }
function installAndLaunchOnDevice(args, selectedDevice, packageNameWithSuffix, packageName, adbPath) { function installAndLaunchOnDevice(args, selectedDevice, packageNameWithSuffix, packageName, adbPath) {
tryRunAdbReverse(selectedDevice); tryRunAdbReverse(args.port, selectedDevice);
tryInstallAppOnDevice(args, selectedDevice); tryInstallAppOnDevice(args, selectedDevice);
tryLaunchAppOnDevice(selectedDevice, packageNameWithSuffix, packageName, adbPath, args.mainActivity); tryLaunchAppOnDevice(selectedDevice, packageNameWithSuffix, packageName, adbPath, args.mainActivity);
} }
@ -226,7 +226,7 @@ function runOnAllDevices(args, cmd, packageNameWithSuffix, packageName, adbPath)
const devices = adb.getDevices(); const devices = adb.getDevices();
if (devices && devices.length > 0) { if (devices && devices.length > 0) {
devices.forEach((device) => { devices.forEach((device) => {
tryRunAdbReverse(device); tryRunAdbReverse(args.port, device);
tryLaunchAppOnDevice(device, packageNameWithSuffix, packageName, adbPath, args.mainActivity); tryLaunchAppOnDevice(device, packageNameWithSuffix, packageName, adbPath, args.mainActivity);
}); });
} else { } else {
@ -317,5 +317,9 @@ module.exports = {
}, { }, {
command: '--no-packager', command: '--no-packager',
description: 'Do not launch packager while building', description: 'Do not launch packager while building',
}, {
command: '--port [number]',
default: 8081,
parse: (val: string) => Number(val),
}], }],
}; };