0
# CLI Commands
1
2
Core Android development commands integrated with React Native CLI, providing comprehensive build, run, and logging functionality for Android development workflows.
3
4
## Capabilities
5
6
### run-android Command
7
8
Builds and launches React Native apps on Android devices or emulators with comprehensive configuration options.
9
10
```typescript { .api }
11
/**
12
* Builds your app and starts it on a connected Android emulator or device
13
* @param _argv - Command line arguments array
14
* @param config - React Native CLI configuration object
15
* @param args - Parsed command options
16
*/
17
async function runAndroid(_argv: Array<string>, config: Config, args: RunAndroidFlags): Promise<void>;
18
19
interface RunAndroidFlags extends BuildFlags {
20
/** Application ID to launch after build */
21
appId: string;
22
/** Application ID suffix */
23
appIdSuffix: string;
24
/** Name of the activity to start */
25
mainActivity?: string;
26
/** Metro Bundler port (default: 8081) */
27
port: number;
28
/** Terminal path for Metro Bundler */
29
terminal?: string;
30
/** Do not launch packager while running the app */
31
packager?: boolean;
32
/** Explicitly set device to use by name */
33
device?: string;
34
/** DEPRECATED: Device ID (use --device instead) */
35
deviceId?: string;
36
/** List all available devices and let user choose */
37
listDevices?: boolean;
38
/** Path to pre-built .apk binary */
39
binaryPath?: string;
40
/** User Profile ID for app installation */
41
user?: number | string;
42
}
43
```
44
45
**Command Options:**
46
- `--no-packager`: Do not launch packager while running the app
47
- `--port <number>`: Metro Bundler port (default: 8081)
48
- `--terminal <string>`: Terminal path for Metro Bundler
49
- `--appId <string>`: Application ID to launch after build
50
- `--appIdSuffix <string>`: Application ID suffix
51
- `--main-activity <string>`: Name of the activity to start
52
- `--device <string>`: Explicitly set device to use by name
53
- `--deviceId <string>`: **DEPRECATED** Device ID (use --device instead)
54
- `--list-devices`: List all available devices and let user choose
55
- `--binary-path <string>`: Path to pre-built .apk binary
56
- `--user <number>`: User Profile ID for app installation
57
- Plus all build-android command options
58
59
**Usage Examples:**
60
61
```bash
62
# Run on default device
63
npx react-native run-android
64
65
# Run on specific device
66
npx react-native run-android --device "Pixel_4_API_30"
67
68
# Run with interactive device selection
69
npx react-native run-android --list-devices
70
71
# Run with specific port and no packager
72
npx react-native run-android --port 8082 --no-packager
73
74
# Run pre-built APK
75
npx react-native run-android --binary-path ./android/app/build/outputs/apk/debug/app-debug.apk
76
```
77
78
### build-android Command
79
80
Builds React Native Android apps with various configuration options and Gradle task support.
81
82
```typescript { .api }
83
/**
84
* Builds your app
85
* @param _argv - Command line arguments array
86
* @param config - React Native CLI configuration object
87
* @param args - Parsed build options
88
*/
89
async function buildAndroid(_argv: Array<string>, config: Config, args: BuildFlags): Promise<void>;
90
91
interface BuildFlags {
92
/** Specify app's build variant */
93
mode?: string;
94
/** Build native libraries only for current device architecture for debug builds */
95
activeArchOnly?: boolean;
96
/** Run custom Gradle tasks (comma-separated) */
97
tasks?: Array<string>;
98
/** Custom params passed to gradle build command (space-separated) */
99
extraParams?: Array<string>;
100
/** Explicitly select build type and flavour to use before running a build */
101
interactive?: boolean;
102
}
103
104
/**
105
* Execute Gradle build with specified arguments
106
* @param gradleArgs - Arguments to pass to Gradle
107
* @param sourceDir - Android source directory path
108
*/
109
function build(gradleArgs: string[], sourceDir: string): void;
110
```
111
112
**Command Options:**
113
- `--mode <string>`: Specify app's build variant (debug, release, etc.)
114
- `--tasks <list>`: Run custom Gradle tasks (comma-separated)
115
- `--active-arch-only`: Build native libraries only for current device architecture for debug builds
116
- `--extra-params <string>`: Custom params passed to gradle build command (space-separated)
117
- `-i --interactive`: Explicitly select build type and flavour to use before running a build
118
119
**Usage Examples:**
120
121
```bash
122
# Build debug variant
123
npx react-native build-android
124
125
# Build release variant
126
npx react-native build-android --mode release
127
128
# Build with custom tasks
129
npx react-native build-android --tasks assembleDebug,bundleDebug
130
131
# Interactive build selection
132
npx react-native build-android --interactive
133
134
# Build with extra Gradle parameters
135
npx react-native build-android --extra-params "--stacktrace --info"
136
```
137
138
### log-android Command
139
140
Starts Android logging using logkitty for formatted log output.
141
142
```typescript { .api }
143
/**
144
* Starts logkitty for Android log viewing
145
*/
146
async function logAndroid(): Promise<void>;
147
```
148
149
**Usage Examples:**
150
151
```bash
152
# Start Android logging
153
npx react-native log-android
154
```
155
156
## Internal Functions
157
158
### App Installation and Launch
159
160
```typescript { .api }
161
/**
162
* Install APK on specified Android device
163
* @param args - Command arguments with installation options
164
* @param adbPath - Path to ADB executable
165
* @param device - Target device identifier
166
* @param androidProject - Android project configuration
167
* @param selectedTask - Optional Gradle task name
168
*/
169
function tryInstallAppOnDevice(
170
args: RunAndroidFlags,
171
adbPath: string,
172
device: string,
173
androidProject: AndroidProject,
174
selectedTask?: string,
175
): void;
176
177
/**
178
* Launch installed app on Android device
179
* @param device - Target device identifier
180
* @param androidProject - Android project configuration
181
* @param adbPath - Path to ADB executable
182
* @param args - Command arguments with launch options
183
*/
184
function tryLaunchAppOnDevice(
185
device: string | void,
186
androidProject: AndroidProject,
187
adbPath: string,
188
args: RunAndroidFlags,
189
): void;
190
191
/**
192
* Execute installation on all connected devices
193
* @param args - Command arguments
194
* @param cmd - Command to execute
195
* @param adbPath - Path to ADB executable
196
* @param androidProject - Android project configuration
197
*/
198
async function runOnAllDevices(
199
args: RunAndroidFlags,
200
cmd: string,
201
adbPath: string,
202
androidProject: AndroidProject,
203
): Promise<void>;
204
```
205
206
### Task Name Generation
207
208
```typescript { .api }
209
/**
210
* Generate Gradle task names for builds
211
* @param appName - Application name
212
* @param mode - Build mode (debug, release, etc.)
213
* @param tasks - Custom task names
214
* @param taskPrefix - Task prefix type
215
* @returns Array of Gradle task names
216
*/
217
function getTaskNames(
218
appName: string,
219
mode: BuildFlags['mode'] = 'debug',
220
tasks: BuildFlags['tasks'],
221
taskPrefix: 'assemble' | 'install' | 'bundle',
222
): Array<string>;
223
```
224
225
### Port Management
226
227
```typescript { .api }
228
/**
229
* Find an available port for development server
230
* @param port - Preferred port number
231
* @returns Promise resolving to available port
232
*/
233
function getAvailableDevicePort(port?: number): Promise<number>;
234
```
235
236
### Utility Functions
237
238
```typescript { .api }
239
/**
240
* Convert string to PascalCase format
241
* @param value - Input string to convert
242
* @returns PascalCase formatted string
243
*/
244
function toPascalCase(value: string): string;
245
```