Skip to content

Commit 1cc7ef0

Browse files
burgalonFacebook Github Bot 9
authored andcommitted
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 facebook#8345 Differential Revision: D3475782 Pulled By: mkonicek fbshipit-source-id: 6f2c5a3e6d61cbeec914175686d2a7909d22a957
1 parent a2c1170 commit 1cc7ef0

File tree

1 file changed

+31
-5
lines changed

1 file changed

+31
-5
lines changed

local-cli/runAndroid/runAndroid.js

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ function _runAndroid(argv, config, resolve, reject) {
6262
console.log(chalk.bold(`Starting JS server...`));
6363
startServerInNewWindow();
6464
}
65-
buildAndRun(args, reject);
65+
run(args, reject);
6666
}));
6767
}
6868

@@ -71,10 +71,38 @@ function checkAndroid(args) {
7171
return fs.existsSync(path.join(args.root, 'android/gradlew'));
7272
}
7373

74+
function getAdbPath() {
75+
return process.env.ANDROID_HOME
76+
? process.env.ANDROID_HOME + '/platform-tools/adb'
77+
: 'adb';
78+
}
79+
80+
// Runs ADB reverse tcp:8081 tcp:8081 to allow loading the jsbundle from the packager
81+
function tryRunAdbReverse() {
82+
try {
83+
const adbPath = getAdbPath();
84+
const adbArgs = ['reverse', 'tcp:8081', 'tcp:8081'];
85+
86+
console.log(chalk.bold(
87+
`Running ${adbPath} ${adbArgs.join(' ')}`
88+
));
89+
90+
child_process.execFileSync(adbPath, adbArgs, {
91+
stdio: [process.stdin, process.stdout, process.stderr],
92+
});
93+
} catch(e) {
94+
console.log(chalk.yellow(
95+
`Could not run adb reverse: ${e.message}`
96+
));
97+
}
98+
}
99+
74100
// Builds the app and runs it on a connected emulator / device.
75-
function buildAndRun(args, reject) {
101+
function run(args, reject) {
76102
process.chdir(path.join(args.root, 'android'));
77103
try {
104+
tryRunAdbReverse();
105+
78106
const cmd = process.platform.startsWith('win')
79107
? 'gradlew.bat'
80108
: './gradlew';
@@ -126,9 +154,7 @@ function buildAndRun(args, reject) {
126154
'utf8'
127155
).match(/package="(.+?)"/)[1];
128156

129-
const adbPath = process.env.ANDROID_HOME
130-
? process.env.ANDROID_HOME + '/platform-tools/adb'
131-
: 'adb';
157+
const adbPath = getAdbPath();
132158

133159
const devices = adb.getDevices();
134160

0 commit comments

Comments
 (0)