Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: remove Gradle task check on run-android #2144

Merged
Show file tree
Hide file tree
Changes from 2 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
8 changes: 8 additions & 0 deletions packages/cli-platform-android/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ Build native libraries only for the current device architecture for debug builds

List all available Android devices and simulators and let you choose one to run the app.


#### `--interactive`

Manually select a task and device/simulator you want to run your app on.

> [!WARNING]
> This flag is running `./gradlew tasks` under the hood, which might take some time for more complex apps. If that affects your project, consider using `--mode` and `--deviceId` flags instead.

### `build-android`

Usage:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ async function buildAndroid(
args.mode,
tasks,
'bundle',
androidProject.sourceDir,
);

if (args.extraParams) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,47 +1,15 @@
import {toPascalCase} from './toPascalCase';
import type {BuildFlags} from '../buildAndroid';
import {getGradleTasks} from './listAndroidTasks';
import {CLIError, logger} from '@react-native-community/cli-tools';

export function getTaskNames(
appName: string,
mode: BuildFlags['mode'] = 'debug',
tasks: BuildFlags['tasks'],
taskPrefix: 'assemble' | 'install' | 'bundle',
sourceDir: string,
): Array<string> {
let appTasks =
const appTasks =
tasks && tasks.length ? tasks : [taskPrefix + toPascalCase(mode)];

// Check against build flavors for "install" task ("assemble" don't care about it so much and will build all)
if (!tasks?.length && taskPrefix === 'install') {
const actionableInstallTasks = getGradleTasks('install', sourceDir);
if (!actionableInstallTasks.find((t) => t.task.includes(appTasks[0]))) {
const installTasksForMode = actionableInstallTasks.filter((t) =>
t.task.toLowerCase().includes(mode),
);
if (!installTasksForMode.length) {
throw new CLIError(
`Couldn't find "${appTasks
.map((taskName) => taskName.replace(taskPrefix, ''))
.join(
', ',
)}" build variant. Available variants are: ${actionableInstallTasks
.map((t) => `"${t.task.replace(taskPrefix, '')}"`)
.join(', ')}.`,
);
}
logger.warn(
`Found multiple tasks for "install" command: ${installTasksForMode
.map((t) => t.task)
.join(', ')}.\nSelecting first available: ${
installTasksForMode[0].task
}.`,
);
appTasks = [installTasksForMode[0].task];
}
}

return appName
? appTasks.map((command) => `${appName}:${command}`)
: appTasks;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@ function runOnSpecificDevice(
args.mode,
args.tasks ?? buildTask,
'install',
androidProject.sourceDir,
);

// using '-x lint' in order to ignore linting errors while building the apk
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {CLIError, prompt} from '@react-native-community/cli-tools';
import {CLIError, getLoader, prompt} from '@react-native-community/cli-tools';
import chalk from 'chalk';
import execa from 'execa';

Expand Down Expand Up @@ -31,11 +31,14 @@ export const getGradleTasks = (
taskType: 'install' | 'build',
sourceDir: string,
) => {
const loader = getLoader();
loader.start('Searching for available Gradle tasks...');
const cmd = process.platform.startsWith('win') ? 'gradlew.bat' : './gradlew';

const out = execa.sync(cmd, ['tasks', '--group', taskType], {
cwd: sourceDir,
}).stdout;
loader.succeed();
return parseTasksFromGradleFile(taskType, out);
TMisiukiewicz marked this conversation as resolved.
Show resolved Hide resolved
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ async function runOnAllDevices(
args.mode,
args.tasks,
'install',
androidProject.sourceDir,
);

if (args.extraParams) {
Expand Down
Loading