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 https://github.com/facebook/react-native/pull/9190 Differential Revision: D3719050 fbshipit-source-id: 269cf8507e067218880aa1e0c0e0e625228e25b5
This commit is contained in:
Родитель
c7d0bc73c2
Коммит
dd6370fed2
|
@ -16,11 +16,6 @@ const isPackagerRunning = require('../util/isPackagerRunning');
|
|||
const Promise = require('promise');
|
||||
const adb = require('./adb');
|
||||
|
||||
// Verifies this is an Android project
|
||||
function checkAndroid(root) {
|
||||
return fs.existsSync(path.join(root, 'android/gradlew'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the app on a connected Android emulator or device.
|
||||
*/
|
||||
|
@ -51,11 +46,16 @@ 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(' ')}`
|
||||
));
|
||||
|
@ -63,7 +63,7 @@ function tryRunAdbReverse() {
|
|||
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'
|
||||
|
|
Загрузка…
Ссылка в новой задаче