Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 17 additions & 11 deletions local-cli/runAndroid/runAndroid.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,24 +90,26 @@ function buildAndRun(args) {
'utf8'
).match(/package="(.+?)"/)[1];

const packageNameWithSuffix = args.appIdSuffix ? packageName + '.' + args.appIdSuffix : packageName;

const adbPath = getAdbPath();
if (args.deviceId) {
if (isString(args.deviceId)) {
runOnSpecificDevice(args, cmd, packageName, adbPath);
runOnSpecificDevice(args, cmd, packageNameWithSuffix, packageName, adbPath);
} else {
console.log(chalk.red('Argument missing for parameter --deviceId'));
}
} 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();
if (devices && devices.length > 0) {
if (devices.indexOf(args.deviceId) !== -1) {
buildApk(gradlew);
installAndLaunchOnDevice(args, args.deviceId, packageName, adbPath);
installAndLaunchOnDevice(args, args.deviceId, packageNameWithSuffix, packageName, adbPath);
} else {
console.log('Could not find device with the id: "' + args.deviceId + '".');
console.log('Choose one of the following:');
Expand Down Expand Up @@ -150,9 +152,9 @@ function tryInstallAppOnDevice(args, device) {
}
}

function tryLaunchAppOnDevice(device, packageName, adbPath, mainActivity) {
function tryLaunchAppOnDevice(device, packageNameWithSuffix, packageName, adbPath, mainActivity) {
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(
`Starting the app on ${device} (${adbPath} ${adbArgs.join(' ')})...`
));
Expand All @@ -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);
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 {
const gradleArgs = [];
if (args.variant) {
Expand Down Expand Up @@ -215,14 +217,14 @@ function runOnAllDevices(args, cmd, packageName, adbPath){
if (devices && devices.length > 0) {
devices.forEach((device) => {
tryRunAdbReverse(device);
tryLaunchAppOnDevice(device, packageName, adbPath, args.mainActivity);
tryLaunchAppOnDevice(device, packageNameWithSuffix, packageName, adbPath, args.mainActivity);
});
} else {
try {
// If we cannot execute based on adb devices output, fall back to
// shell am start
const fallbackAdbArgs = [
'shell', 'am', 'start', '-n', packageName + '/.MainActivity'
'shell', 'am', 'start', '-n', packageNameWithSuffix + '/' + packageName + '.MainActivity'
];
console.log(chalk.bold(
`Starting the app (${adbPath} ${fallbackAdbArgs.join(' ')}...`
Expand Down Expand Up @@ -286,6 +288,10 @@ module.exports = {
description: '--flavor has been deprecated. Use --variant instead',
}, {
command: '--variant [string]',
}, {
command: '--appIdSuffix [string]',
description: 'Specify an applicationIdSuffix to launch after build.',
default: '',
}, {
command: '--main-activity [string]',
description: 'Name of the activity to start',
Expand Down