CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-react-native-community--cli-platform-android

Android platform commands for React Native CLI providing run-android, build-android, and log-android commands for managing Android development workflow

Pending
Overview
Eval results
Files

build-system.mddocs/

Build System

Advanced build management for React Native Android projects, including Gradle task selection, build modes, architecture-specific builds, and interactive build configuration.

Capabilities

Core Build Function

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.

Gradle Task Management

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}`);
}

Task Name Generation

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"]

Build Configuration

Build Modes and Variants

Android builds support multiple modes and variants:

  • debug: Development builds with debugging enabled
  • release: Production builds with optimizations
  • staging: Pre-production builds for testing
  • Custom variants: Project-specific build types defined in build.gradle

Architecture-Specific Builds

The activeArchOnly flag enables building native libraries only for the current device's architecture, which:

  • Reduces build time during development
  • Decreases APK size for testing
  • Only applies to debug builds (release builds include all architectures)

Interactive Build Selection

When using the interactive flag, users can:

  • Choose from available build types (debug, release, etc.)
  • Select specific product flavors if defined
  • Combine build types with flavors for complex configurations

Custom Gradle Parameters

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
];

Task Execution Order

Gradle tasks execute in dependency order:

  1. Clean tasks: Remove previous build artifacts
  2. Compile tasks: Compile source code and resources
  3. Assemble tasks: Create APK files
  4. Install tasks: Install APK on devices
  5. Bundle tasks: Create Android App Bundle files

Error Handling

The build system includes comprehensive error handling for:

  • Gradle not found: Missing or misconfigured Gradle installation
  • Android SDK issues: Missing or invalid Android SDK setup
  • Build failures: Compilation errors and dependency issues
  • Device connectivity: Installation failures on target devices
  • Permission issues: File system and device permissions

Advanced Usage

Custom Build Workflows

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');

Build System Integration

The build system integrates with:

  • React Native CLI: Automatic build configuration
  • Metro Bundler: JavaScript bundle integration
  • Native Modules: Automatic linking and compilation
  • Android Gradle Plugin: Latest build tools support
  • Kotlin/Java: Multi-language project support

Install with Tessl CLI

npx tessl i tessl/npm-react-native-community--cli-platform-android

docs

build-system.md

commands.md

device-management.md

emulator-management.md

index.md

network-configuration.md

project-configuration.md

tile.json