0
# Android Platform Types
1
2
Comprehensive Android platform configuration types covering project structure, dependency management, C++ modules, and build configuration with full React Native integration.
3
4
## Capabilities
5
6
### Android Project Configuration
7
8
Complete Android project configuration defining app structure, build settings, and development workflow parameters.
9
10
```typescript { .api }
11
/**
12
* Complete Android project configuration
13
*/
14
interface AndroidProjectConfig {
15
/** Source directory containing Java/Kotlin code (e.g., "android/app/src/main/java") */
16
sourceDir: string;
17
/** Application name as defined in Android manifest */
18
appName: string;
19
/** Java package name (e.g., "com.mycompany.myapp") */
20
packageName: string;
21
/** Android application ID for builds */
22
applicationId: string;
23
/** Main activity class name */
24
mainActivity: string;
25
/** Gradle dependency configuration (e.g., "implementation", "api") */
26
dependencyConfiguration?: string;
27
/** Additional command parameters for watch mode */
28
watchModeCommandParams?: string[];
29
/** Asset directories for this platform */
30
assets: string[];
31
}
32
```
33
34
**Usage Examples:**
35
36
```typescript
37
import { AndroidProjectConfig } from "@react-native-community/cli-types";
38
39
// Standard Android project configuration
40
const androidConfig: AndroidProjectConfig = {
41
sourceDir: "android/app/src/main/java",
42
appName: "MyReactNativeApp",
43
packageName: "com.mycompany.myapp",
44
applicationId: "com.mycompany.myapp",
45
mainActivity: "MainActivity",
46
dependencyConfiguration: "implementation",
47
watchModeCommandParams: ["--verbose"],
48
assets: ["./android/app/src/main/assets"]
49
};
50
51
// Validate Android configuration
52
function validateAndroidConfig(config: AndroidProjectConfig): boolean {
53
const requiredFields = ['sourceDir', 'appName', 'packageName', 'applicationId', 'mainActivity'];
54
return requiredFields.every(field => !!config[field as keyof AndroidProjectConfig]);
55
}
56
57
// Get app identifiers
58
function getAndroidIdentifiers(config: AndroidProjectConfig) {
59
return {
60
appName: config.appName,
61
packageName: config.packageName,
62
applicationId: config.applicationId,
63
mainActivity: config.mainActivity
64
};
65
}
66
```
67
68
### Android Project Parameters
69
70
Input parameters for configuring Android projects, with optional fields for flexibility.
71
72
```typescript { .api }
73
/**
74
* Parameters for Android project configuration with optional fields
75
*/
76
type AndroidProjectParams = {
77
/** Source directory (optional, will be detected if not provided) */
78
sourceDir?: string;
79
/** Application name (optional, will be detected from manifest) */
80
appName?: string;
81
/** Path to AndroidManifest.xml (optional, will be detected) */
82
manifestPath?: string;
83
/** Java package name (optional, will be detected from manifest) */
84
packageName?: string;
85
/** Gradle dependency configuration */
86
dependencyConfiguration?: string;
87
/** Additional command parameters for watch mode */
88
watchModeCommandParams?: string[];
89
/** Asset directories */
90
assets?: string[];
91
};
92
```
93
94
**Usage Examples:**
95
96
```typescript
97
import { AndroidProjectParams } from "@react-native-community/cli-types";
98
99
// Minimal Android parameters (auto-detection)
100
const minimalParams: AndroidProjectParams = {
101
dependencyConfiguration: "implementation"
102
};
103
104
// Full Android parameters
105
const fullParams: AndroidProjectParams = {
106
sourceDir: "android/app/src/main/java",
107
appName: "MyApp",
108
manifestPath: "android/app/src/main/AndroidManifest.xml",
109
packageName: "com.mycompany.myapp",
110
dependencyConfiguration: "api",
111
watchModeCommandParams: ["--info", "--stacktrace"],
112
assets: ["./assets", "./android/app/src/main/assets"]
113
};
114
115
// Create parameters from existing config
116
function paramsFromConfig(config: AndroidProjectConfig): AndroidProjectParams {
117
return {
118
sourceDir: config.sourceDir,
119
appName: config.appName,
120
packageName: config.packageName,
121
dependencyConfiguration: config.dependencyConfiguration,
122
watchModeCommandParams: config.watchModeCommandParams,
123
assets: config.assets
124
};
125
}
126
```
127
128
### Android Dependency Configuration
129
130
Comprehensive dependency configuration supporting Java/Kotlin libraries, C++ modules, and React Native component descriptors.
131
132
```typescript { .api }
133
/**
134
* Complete Android dependency configuration supporting various module types
135
*/
136
type AndroidDependencyConfig = {
137
/** Source directory of the dependency */
138
sourceDir: string;
139
/** Import path for the package in Java/Kotlin (null if no import needed) */
140
packageImportPath: string | null;
141
/** Package instance creation code (null if no instance needed) */
142
packageInstance: string | null;
143
/** Gradle dependency configuration (e.g., "implementation", "api") */
144
dependencyConfiguration?: string;
145
/** Build types this dependency supports */
146
buildTypes: string[];
147
/** Library name for native modules (null for non-native) */
148
libraryName?: string | null;
149
/** Component descriptors for Fabric components (null if not applicable) */
150
componentDescriptors?: string[] | null;
151
/** Path to CMakeLists.txt for C++ modules (null if no CMake) */
152
cmakeListsPath?: string | null;
153
/** CMake module name for C++ modules (null if no CMake) */
154
cxxModuleCMakeListsModuleName?: string | null;
155
/** CMake lists path for C++ modules (null if no CMake) */
156
cxxModuleCMakeListsPath?: string | null;
157
/** Header name for C++ modules (null if no C++) */
158
cxxModuleHeaderName?: string | null;
159
/** Whether this is a pure C++ dependency (no Java/Kotlin code) */
160
isPureCxxDependency?: boolean;
161
};
162
```
163
164
**Usage Examples:**
165
166
```typescript
167
import { AndroidDependencyConfig } from "@react-native-community/cli-types";
168
169
// Java/Kotlin library dependency
170
const javaLibraryDep: AndroidDependencyConfig = {
171
sourceDir: "android",
172
packageImportPath: "com.mylibrary.MyLibraryPackage",
173
packageInstance: "new MyLibraryPackage()",
174
dependencyConfiguration: "implementation",
175
buildTypes: ["debug", "release"],
176
libraryName: "mylibrary",
177
componentDescriptors: null,
178
cmakeListsPath: null,
179
cxxModuleCMakeListsModuleName: null,
180
cxxModuleCMakeListsPath: null,
181
cxxModuleHeaderName: null,
182
isPureCxxDependency: false
183
};
184
185
// C++ module dependency
186
const cppModuleDep: AndroidDependencyConfig = {
187
sourceDir: "android",
188
packageImportPath: null,
189
packageInstance: null,
190
dependencyConfiguration: "implementation",
191
buildTypes: ["debug", "release"],
192
libraryName: "mycppmodule",
193
componentDescriptors: null,
194
cmakeListsPath: "android/CMakeLists.txt",
195
cxxModuleCMakeListsModuleName: "mycppmodule",
196
cxxModuleCMakeListsPath: "android/src/main/cpp/CMakeLists.txt",
197
cxxModuleHeaderName: "mycppmodule.h",
198
isPureCxxDependency: true
199
};
200
201
// Fabric component dependency
202
const fabricComponentDep: AndroidDependencyConfig = {
203
sourceDir: "android",
204
packageImportPath: "com.mycomponent.MyComponentPackage",
205
packageInstance: "new MyComponentPackage()",
206
dependencyConfiguration: "implementation",
207
buildTypes: ["debug", "release"],
208
libraryName: "mycomponent",
209
componentDescriptors: ["MyComponentComponentDescriptor"],
210
cmakeListsPath: null,
211
cxxModuleCMakeListsModuleName: null,
212
cxxModuleCMakeListsPath: null,
213
cxxModuleHeaderName: null,
214
isPureCxxDependency: false
215
};
216
217
// Check dependency type
218
function analyzeDependencyType(dep: AndroidDependencyConfig): string {
219
if (dep.isPureCxxDependency) return "Pure C++ Module";
220
if (dep.componentDescriptors?.length) return "Fabric Component";
221
if (dep.cmakeListsPath) return "Hybrid Java/C++ Module";
222
if (dep.packageImportPath) return "Java/Kotlin Library";
223
return "Unknown";
224
}
225
```
226
227
### Android Dependency Parameters
228
229
Input parameters for configuring Android dependencies with optional fields for auto-detection.
230
231
```typescript { .api }
232
/**
233
* Parameters for Android dependency configuration with optional auto-detection fields
234
*/
235
type AndroidDependencyParams = {
236
/** Source directory (optional, will be detected) */
237
sourceDir?: string;
238
/** Path to AndroidManifest.xml (optional, will be detected) */
239
manifestPath?: string;
240
/** Java package name (optional, will be detected) */
241
packageName?: string;
242
/** Gradle dependency configuration */
243
dependencyConfiguration?: string;
244
/** Import path for the package (optional, will be detected) */
245
packageImportPath?: string;
246
/** Package instance creation code (optional, will be detected) */
247
packageInstance?: string;
248
/** Build types this dependency supports */
249
buildTypes?: string[];
250
/** Library name for native modules */
251
libraryName?: string | null;
252
/** Component descriptors for Fabric components */
253
componentDescriptors?: string[] | null;
254
/** Path to CMakeLists.txt for C++ modules */
255
cmakeListsPath?: string | null;
256
/** CMake module name for C++ modules */
257
cxxModuleCMakeListsModuleName?: string | null;
258
/** CMake lists path for C++ modules */
259
cxxModuleCMakeListsPath?: string | null;
260
/** Header name for C++ modules */
261
cxxModuleHeaderName?: string | null;
262
};
263
```
264
265
**Usage Examples:**
266
267
```typescript
268
import { AndroidDependencyParams } from "@react-native-community/cli-types";
269
270
// Minimal parameters (auto-detection)
271
const minimalDependencyParams: AndroidDependencyParams = {
272
dependencyConfiguration: "implementation"
273
};
274
275
// Parameters for Java library
276
const javaLibraryParams: AndroidDependencyParams = {
277
sourceDir: "android",
278
packageImportPath: "com.mylibrary.MyLibraryPackage",
279
packageInstance: "new MyLibraryPackage()",
280
dependencyConfiguration: "implementation",
281
buildTypes: ["debug", "release"],
282
libraryName: "mylibrary"
283
};
284
285
// Parameters for C++ module
286
const cppModuleParams: AndroidDependencyParams = {
287
sourceDir: "android",
288
dependencyConfiguration: "implementation",
289
libraryName: "mycppmodule",
290
cmakeListsPath: "android/CMakeLists.txt",
291
cxxModuleCMakeListsModuleName: "mycppmodule",
292
cxxModuleHeaderName: "mycppmodule.h"
293
};
294
295
// Convert parameters to full config (simulated auto-detection)
296
function simulateConfigGeneration(
297
params: AndroidDependencyParams,
298
detectedValues: Partial<AndroidDependencyConfig>
299
): AndroidDependencyConfig {
300
return {
301
sourceDir: params.sourceDir || detectedValues.sourceDir || "android",
302
packageImportPath: params.packageImportPath || detectedValues.packageImportPath || null,
303
packageInstance: params.packageInstance || detectedValues.packageInstance || null,
304
dependencyConfiguration: params.dependencyConfiguration || "implementation",
305
buildTypes: params.buildTypes || ["debug", "release"],
306
libraryName: params.libraryName || detectedValues.libraryName || null,
307
componentDescriptors: params.componentDescriptors || null,
308
cmakeListsPath: params.cmakeListsPath || null,
309
cxxModuleCMakeListsModuleName: params.cxxModuleCMakeListsModuleName || null,
310
cxxModuleCMakeListsPath: params.cxxModuleCMakeListsPath || null,
311
cxxModuleHeaderName: params.cxxModuleHeaderName || null,
312
isPureCxxDependency: !!(params.cmakeListsPath && !params.packageImportPath)
313
};
314
}
315
```
316
317
### Platform Integration
318
319
How Android types integrate with the broader platform configuration system.
320
321
**Usage Examples:**
322
323
```typescript
324
import { Config, AndroidProjectParams, AndroidDependencyParams } from "@react-native-community/cli-types";
325
326
// The Android platform configuration is accessed through Config.platforms.android
327
// Note: AndroidPlatformConfig type is not exported, but the platform is accessible
328
329
// Generate Android project config from parameters
330
function generateAndroidProjectConfig(
331
config: Config,
332
projectRoot: string,
333
params?: AndroidProjectParams
334
): AndroidProjectConfig | void {
335
return config.platforms.android.projectConfig(projectRoot, params);
336
}
337
338
// Generate Android dependency config
339
function generateAndroidDependencyConfig(
340
config: Config,
341
dependency: string,
342
params: AndroidDependencyParams
343
): AndroidDependencyConfig | void {
344
return config.platforms.android.dependencyConfig(dependency, params);
345
}
346
347
// Check if project has Android support
348
function hasAndroidSupport(config: Config): boolean {
349
return !!config.project.android;
350
}
351
352
// Access Android platform through config
353
function getAndroidSettings(config: Config) {
354
const androidPlatform = config.platforms.android;
355
return {
356
npmPackageName: androidPlatform.npmPackageName,
357
hasProjectConfig: typeof androidPlatform.projectConfig === 'function',
358
hasDependencyConfig: typeof androidPlatform.dependencyConfig === 'function'
359
};
360
}
361
```