Skip to content

Commit 0705f50

Browse files
committed
fix: use variant arg in build-android command
1 parent f308a56 commit 0705f50

File tree

3 files changed

+38
-20
lines changed

3 files changed

+38
-20
lines changed

docs/commands.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,8 @@ Override the root directory for the Android build (which contains the android di
323323

324324
#### `--variant <string>`
325325

326+
> **DEPRECATED** – use "mode" instead
327+
326328
> default: 'debug'
327329
328330
Specify your app's build variant.

packages/cli-platform-android/src/commands/buildAndroid/index.ts

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
import {Config} from '@react-native-community/cli-types';
88
import execa from 'execa';
99
import {getAndroidProject} from '../../config/getAndroidProject';
10-
import {getTaskNames, toPascalCase} from '../runAndroid/runOnAllDevices';
10+
import {toPascalCase} from '../runAndroid/runOnAllDevices';
1111
import adb from '../runAndroid/adb';
1212
import getAdbPath from '../runAndroid/getAdbPath';
1313
import {startServerInNewWindow} from './startServerInNewWindow';
@@ -23,6 +23,21 @@ export interface BuildFlags {
2323
extraParams?: Array<string>;
2424
}
2525

26+
export function getTaskNames(
27+
appName: string,
28+
mode: BuildFlags['mode'],
29+
variant: BuildFlags['variant'],
30+
tasks: BuildFlags['tasks'],
31+
taskPrefix: 'assemble' | 'install',
32+
): Array<string> {
33+
const appMode = mode || variant || 'debug';
34+
const appTasks = tasks || [taskPrefix + toPascalCase(appMode)];
35+
36+
return appName
37+
? appTasks.map((command) => `${appName}:${command}`)
38+
: appTasks;
39+
}
40+
2641
export async function runPackager(args: BuildFlags, config: Config) {
2742
if (!args.packager) {
2843
return;
@@ -58,17 +73,19 @@ async function buildAndroid(
5873
);
5974
}
6075

61-
const mode = args.variant || args.mode;
62-
6376
if (args.tasks && args.mode) {
6477
logger.warn(
6578
'Both "tasks" and "mode" parameters were passed to "build" command. Using "tasks" for building the app.',
6679
);
6780
}
6881

69-
const tasks = args.tasks || ['assemble' + toPascalCase(mode)];
70-
71-
let gradleArgs = getTaskNames(androidProject.appName, tasks);
82+
let gradleArgs = getTaskNames(
83+
androidProject.appName,
84+
args.mode,
85+
args.variant,
86+
args.tasks,
87+
'assemble',
88+
);
7289

7390
if (args.extraParams) {
7491
gradleArgs = [...gradleArgs, ...args.extraParams];
@@ -117,7 +134,6 @@ export const options = [
117134
{
118135
name: '--mode <string>',
119136
description: "Specify your app's build variant",
120-
default: 'debug',
121137
},
122138
{
123139
name: '--variant <string>',

packages/cli-platform-android/src/commands/runAndroid/runOnAllDevices.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,7 @@ import tryLaunchAppOnDevice from './tryLaunchAppOnDevice';
1616
import tryLaunchEmulator from './tryLaunchEmulator';
1717
import tryInstallAppOnDevice from './tryInstallAppOnDevice';
1818
import {Flags} from '.';
19-
20-
export function getTaskNames(
21-
appName: string,
22-
commands: Array<string>,
23-
): Array<string> {
24-
return appName
25-
? commands.map((command) => `${appName}:${command}`)
26-
: commands;
27-
}
19+
import {getTaskNames} from '../buildAndroid';
2820

2921
export function toPascalCase(value: string) {
3022
return value !== '' ? value[0].toUpperCase() + value.slice(1) : value;
@@ -54,13 +46,21 @@ async function runOnAllDevices(
5446
);
5547
}
5648
}
49+
if (args.variant) {
50+
logger.warn(
51+
'"variant" flag is deprecated and will be removed in future release. Please switch to "mode" flag.',
52+
);
53+
}
5754

5855
try {
5956
if (!args.binaryPath) {
60-
const tasks = args.tasks || [
61-
'install' + toPascalCase(args.mode ?? 'debug'),
62-
];
63-
let gradleArgs = getTaskNames(androidProject.appName, tasks);
57+
let gradleArgs = getTaskNames(
58+
androidProject.appName,
59+
args.mode,
60+
args.variant,
61+
args.tasks,
62+
'install',
63+
);
6464

6565
if (args.extraParams) {
6666
gradleArgs = [...gradleArgs, ...args.extraParams];

0 commit comments

Comments
 (0)