Allow specifying an appIdSuffix to run-android
Summary: Motivation Currently react-native run-android instals and starts your app, but if you have more than one variant, it doesn't know which one to start. This allows developers to pass in the suffix specified in build.gradle, so that the correct app is started. Test Plan verify that `react-native run-android` runs properly verify that `react-native run-android --appIdSuffix validSuffix` runs properly Closes https://github.com/facebook/react-native/pull/13169 Differential Revision: D4823391 Pulled By: ericvicenti fbshipit-source-id: 31ed35fd79403804b4781e81eb49f1c4627d7f8e
This commit is contained in:
parent
ff95805657
commit
d8f23f79c7
|
@ -90,24 +90,26 @@ function buildAndRun(args) {
|
||||||
'utf8'
|
'utf8'
|
||||||
).match(/package="(.+?)"/)[1];
|
).match(/package="(.+?)"/)[1];
|
||||||
|
|
||||||
|
const packageNameWithSuffix = args.appIdSuffix ? packageName + '.' + args.appIdSuffix : packageName;
|
||||||
|
|
||||||
const adbPath = getAdbPath();
|
const adbPath = getAdbPath();
|
||||||
if (args.deviceId) {
|
if (args.deviceId) {
|
||||||
if (isString(args.deviceId)) {
|
if (isString(args.deviceId)) {
|
||||||
runOnSpecificDevice(args, cmd, packageName, adbPath);
|
runOnSpecificDevice(args, cmd, packageNameWithSuffix, packageName, adbPath);
|
||||||
} else {
|
} else {
|
||||||
console.log(chalk.red('Argument missing for parameter --deviceId'));
|
console.log(chalk.red('Argument missing for parameter --deviceId'));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
runOnAllDevices(args, cmd, packageName, adbPath);
|
runOnAllDevices(args, cmd, packageNameWithSuffix, packageName, adbPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function runOnSpecificDevice(args, gradlew, packageName, adbPath) {
|
function runOnSpecificDevice(args, gradlew, packageNameWithSuffix, packageName, adbPath) {
|
||||||
let devices = adb.getDevices();
|
let devices = adb.getDevices();
|
||||||
if (devices && devices.length > 0) {
|
if (devices && devices.length > 0) {
|
||||||
if (devices.indexOf(args.deviceId) !== -1) {
|
if (devices.indexOf(args.deviceId) !== -1) {
|
||||||
buildApk(gradlew);
|
buildApk(gradlew);
|
||||||
installAndLaunchOnDevice(args, args.deviceId, packageName, adbPath);
|
installAndLaunchOnDevice(args, args.deviceId, packageNameWithSuffix, packageName, adbPath);
|
||||||
} else {
|
} else {
|
||||||
console.log('Could not find device with the id: "' + args.deviceId + '".');
|
console.log('Could not find device with the id: "' + args.deviceId + '".');
|
||||||
console.log('Choose one of the following:');
|
console.log('Choose one of the following:');
|
||||||
|
@ -150,9 +152,9 @@ function tryInstallAppOnDevice(args, device) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function tryLaunchAppOnDevice(device, packageName, adbPath, mainActivity) {
|
function tryLaunchAppOnDevice(device, packageNameWithSuffix, packageName, adbPath, mainActivity) {
|
||||||
try {
|
try {
|
||||||
const adbArgs = ['-s', device, 'shell', 'am', 'start', '-n', packageName + '/.' + mainActivity];
|
const adbArgs = ['-s', device, 'shell', 'am', 'start', '-n', packageNameWithSuffix + '/' + packageName + '.' + mainActivity];
|
||||||
console.log(chalk.bold(
|
console.log(chalk.bold(
|
||||||
`Starting the app on ${device} (${adbPath} ${adbArgs.join(' ')})...`
|
`Starting the app on ${device} (${adbPath} ${adbArgs.join(' ')})...`
|
||||||
));
|
));
|
||||||
|
@ -164,13 +166,13 @@ function tryLaunchAppOnDevice(device, packageName, adbPath, mainActivity) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function installAndLaunchOnDevice(args, selectedDevice, packageName, adbPath) {
|
function installAndLaunchOnDevice(args, selectedDevice, packageNameWithSuffix, packageName, adbPath) {
|
||||||
tryRunAdbReverse(selectedDevice);
|
tryRunAdbReverse(selectedDevice);
|
||||||
tryInstallAppOnDevice(args, selectedDevice);
|
tryInstallAppOnDevice(args, selectedDevice);
|
||||||
tryLaunchAppOnDevice(selectedDevice, packageName, adbPath, args.mainActivity);
|
tryLaunchAppOnDevice(selectedDevice, packageNameWithSuffix, packageName, adbPath, args.mainActivity);
|
||||||
}
|
}
|
||||||
|
|
||||||
function runOnAllDevices(args, cmd, packageName, adbPath){
|
function runOnAllDevices(args, cmd, packageNameWithSuffix, packageName, adbPath){
|
||||||
try {
|
try {
|
||||||
const gradleArgs = [];
|
const gradleArgs = [];
|
||||||
if (args.variant) {
|
if (args.variant) {
|
||||||
|
@ -215,14 +217,14 @@ function runOnAllDevices(args, cmd, packageName, adbPath){
|
||||||
if (devices && devices.length > 0) {
|
if (devices && devices.length > 0) {
|
||||||
devices.forEach((device) => {
|
devices.forEach((device) => {
|
||||||
tryRunAdbReverse(device);
|
tryRunAdbReverse(device);
|
||||||
tryLaunchAppOnDevice(device, packageName, adbPath, args.mainActivity);
|
tryLaunchAppOnDevice(device, packageNameWithSuffix, packageName, adbPath, args.mainActivity);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
// If we cannot execute based on adb devices output, fall back to
|
// If we cannot execute based on adb devices output, fall back to
|
||||||
// shell am start
|
// shell am start
|
||||||
const fallbackAdbArgs = [
|
const fallbackAdbArgs = [
|
||||||
'shell', 'am', 'start', '-n', packageName + '/.MainActivity'
|
'shell', 'am', 'start', '-n', packageNameWithSuffix + '/' + packageName + '.MainActivity'
|
||||||
];
|
];
|
||||||
console.log(chalk.bold(
|
console.log(chalk.bold(
|
||||||
`Starting the app (${adbPath} ${fallbackAdbArgs.join(' ')}...`
|
`Starting the app (${adbPath} ${fallbackAdbArgs.join(' ')}...`
|
||||||
|
@ -286,6 +288,10 @@ module.exports = {
|
||||||
description: '--flavor has been deprecated. Use --variant instead',
|
description: '--flavor has been deprecated. Use --variant instead',
|
||||||
}, {
|
}, {
|
||||||
command: '--variant [string]',
|
command: '--variant [string]',
|
||||||
|
}, {
|
||||||
|
command: '--appIdSuffix [string]',
|
||||||
|
description: 'Specify an applicationIdSuffix to launch after build.',
|
||||||
|
default: '',
|
||||||
}, {
|
}, {
|
||||||
command: '--main-activity [string]',
|
command: '--main-activity [string]',
|
||||||
description: 'Name of the activity to start',
|
description: 'Name of the activity to start',
|
||||||
|
|
Loading…
Reference in New Issue