Permalink
Browse files

Ask for device when using adb with run-android

Summary:
Sometimes adb see many devices (see: http://puu.sh/qoASz/c13f010dd0.jpg) and it can't `adb reverse` because of that (see: http://puu.sh/qoAR1/8412dfe25a.jpg)

So I've added the possibility to choose a device when you `run-android` your app.

Final result: http://puu.sh/qoB12/329d5c27db.jpg
Closes #9190

Differential Revision: D3719050

fbshipit-source-id: 269cf8507e067218880aa1e0c0e0e625228e25b5
  • Loading branch information...
1 parent c7d0bc7 commit dd6370fed2bb5c6e10660ab7ecca33c95c198311 @jr-k jr-k committed with Facebook Github Bot 7 Aug 16, 2016
Showing with 8 additions and 8 deletions.
  1. +8 −8 local-cli/runAndroid/runAndroid.js
@@ -16,11 +16,6 @@ const isPackagerRunning = require('../util/isPackagerRunning');
const Promise = require('promise');
const adb = require('./adb');
-// Verifies this is an Android project
@aakashsigdel
aakashsigdel Aug 17, 2016

Why has been this function definition removed, as it is being called below in line number 23?

-function checkAndroid(root) {
- return fs.existsSync(path.join(root, 'android/gradlew'));
-}
-
/**
* Starts the app on a connected Android emulator or device.
*/
@@ -51,19 +46,24 @@ function getAdbPath() {
}
// Runs ADB reverse tcp:8081 tcp:8081 to allow loading the jsbundle from the packager
-function tryRunAdbReverse() {
+function tryRunAdbReverse(device) {
try {
const adbPath = getAdbPath();
const adbArgs = ['reverse', 'tcp:8081', 'tcp:8081'];
+ // If a device is specified then tell adb to use it
+ if (device) {
+ adbArgs.unshift('-s', device);
+ }
+
console.log(chalk.bold(
`Running ${adbPath} ${adbArgs.join(' ')}`
));
child_process.execFileSync(adbPath, adbArgs, {
stdio: [process.stdin, process.stdout, process.stderr],
});
- } catch(e) {
+ } catch (e) {
console.log(chalk.yellow(
`Could not run adb reverse: ${e.message}`
));
@@ -74,7 +74,7 @@ function tryRunAdbReverse() {
function buildAndRun(args) {
process.chdir(path.join(args.root, 'android'));
try {
- tryRunAdbReverse();
+ adb.getDevices().map((device) => tryRunAdbReverse(device));
const cmd = process.platform.startsWith('win')
? 'gradlew.bat'

0 comments on commit dd6370f

Please sign in to comment.