Android platform commands for React Native CLI providing run-android, build-android, and log-android commands for managing Android development workflow
—
Advanced build management for React Native Android projects, including Gradle task selection, build modes, architecture-specific builds, and interactive build configuration.
Direct Gradle build execution with custom arguments and source directory specification.
/**
* Execute Gradle build with specified arguments (Internal Function)
* Note: This function is internal and not directly exportable from the main package
* @param gradleArgs - Array of arguments to pass to Gradle
* @param sourceDir - Path to Android source directory
*/
function build(gradleArgs: string[], sourceDir: string): void;Note: This function is internal to the build-android command implementation and is not directly exportable from the main package.
Comprehensive Gradle task discovery, parsing, and interactive selection.
/**
* Gradle task information structure
*/
interface GradleTask {
/** Gradle task name */
task: string;
/** Task description from Gradle */
description: string;
}
/**
* Parse available Gradle tasks from gradle command output
* @param taskType - Type of tasks to parse (install or build)
* @param text - Raw output from Gradle tasks command
* @returns Array of parsed Gradle tasks
*/
function parseTasksFromGradleFile(taskType: 'install' | 'build', text: string): Array<GradleTask>;
/**
* Get available Gradle tasks for the project
* @param taskType - Type of tasks to retrieve (install or build)
* @param sourceDir - Android source directory path
* @returns Array of available Gradle tasks
*/
function getGradleTasks(taskType: 'install' | 'build', sourceDir: string): GradleTask[];
/**
* Interactive prompt for Gradle task selection
* @param taskType - Type of tasks to select from (install or build)
* @param sourceDir - Android source directory path
* @returns Promise resolving to selected task name or undefined if cancelled
*/
async function promptForTaskSelection(
taskType: 'install' | 'build',
sourceDir: string
): Promise<string | undefined>;Usage Examples:
import { getGradleTasks, promptForTaskSelection } from "@react-native-community/cli-platform-android";
// Get available build tasks
const buildTasks = getGradleTasks('build', './android');
console.log("Available build tasks:", buildTasks);
// Get available install tasks
const installTasks = getGradleTasks('install', './android');
console.log("Available install tasks:", installTasks);
// Interactive task selection
const selectedTask = await promptForTaskSelection('build', './android');
if (selectedTask) {
console.log(`Selected task: ${selectedTask}`);
}Automated generation of Gradle task names based on build configuration.
/**
* Generate Gradle task names for builds based on configuration
* @param appName - Application name from Android configuration
* @param mode - Build mode (debug, release, etc.), defaults to 'debug'
* @param tasks - Custom task names to use instead of generated ones
* @param taskPrefix - Type of task to generate (assemble, install, bundle)
* @returns Array of generated Gradle task names
*/
function getTaskNames(
appName: string,
mode: BuildFlags['mode'] = 'debug',
tasks: BuildFlags['tasks'],
taskPrefix: 'assemble' | 'install' | 'bundle',
): Array<string>;
/**
* Build configuration flags interface
*/
interface BuildFlags {
/** Build mode/variant (debug, release, staging, etc.) */
mode?: string;
/** Build only for current device architecture in debug mode */
activeArchOnly?: boolean;
/** Custom Gradle tasks to run instead of generated ones */
tasks?: Array<string>;
/** Additional parameters to pass to Gradle */
extraParams?: Array<string>;
/** Enable interactive build type and flavor selection */
interactive?: boolean;
}Usage Examples:
import { getTaskNames } from "@react-native-community/cli-platform-android";
// Generate assemble tasks for debug build
const assembleTasks = getTaskNames("MyApp", "debug", undefined, "assemble");
console.log("Assemble tasks:", assembleTasks); // ["assembleDebug"]
// Generate install tasks for release build
const installTasks = getTaskNames("MyApp", "release", undefined, "install");
console.log("Install tasks:", installTasks); // ["installRelease"]
// Generate bundle tasks with custom tasks override
const customTasks = ["bundleDebug", "bundleRelease"];
const bundleTasks = getTaskNames("MyApp", "debug", customTasks, "bundle");
console.log("Bundle tasks:", bundleTasks); // ["bundleDebug", "bundleRelease"]Android builds support multiple modes and variants:
The activeArchOnly flag enables building native libraries only for the current device's architecture, which:
When using the interactive flag, users can:
The extraParams option allows passing additional arguments to Gradle:
// Common extra parameters
const extraParams = [
"--stacktrace", // Show detailed error traces
"--info", // Verbose logging
"--parallel", // Enable parallel execution
"--daemon", // Use Gradle daemon
"--offline" // Work offline
];Gradle tasks execute in dependency order:
The build system includes comprehensive error handling for:
import { getGradleTasks, build } from "@react-native-community/cli-platform-android";
// Get all available tasks
const buildTasks = getGradleTasks('build', './android');
const installTasks = getGradleTasks('install', './android');
// Create custom build workflow
const customWorkflow = [
"clean",
"assembleDebug",
"installDebug"
];
// Execute custom workflow
build(customWorkflow, './android');The build system integrates with:
Install with Tessl CLI
npx tessl i tessl/npm-react-native-community--cli-platform-android