Skip to content

Commit daa93cb

Browse files
feat(android): add support for android manifest meta-data (#2399)
1 parent d9c4488 commit daa93cb

File tree

6 files changed

+85
-0
lines changed

6 files changed

+85
-0
lines changed

android/android-manifest.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,17 @@ function generateAndroidManifest(appManifestPath, manifestOutput, fs = nodefs) {
9898
}
9999
}
100100

101+
// https://developer.android.com/guide/topics/manifest/meta-data-element
102+
const metaData = android.metaData;
103+
if (Array.isArray(metaData)) {
104+
const names = ["android:name"];
105+
const attributes = ["android:value"];
106+
const entries = toXML(metaData, names, attributes, attributeNamePrefix);
107+
if (entries.length > 0) {
108+
manifest.application["meta-data"] = entries;
109+
}
110+
}
111+
101112
const builder = new XMLBuilder(xmlOptions);
102113
fs.mkdirSync(path.dirname(manifestOutput), { recursive: true, mode: 0o755 });
103114
fs.writeFileSync(manifestOutput, builder.build(xml));

docs/android.metaData.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
A name-value pair for an item of additional, arbitrary data that can be supplied to the application.
2+
3+
Equivalent to
4+
[`<meta-data>`](https://developer.android.com/guide/topics/manifest/meta-data-element).
5+
6+
Example:
7+
8+
```xml
9+
<application>
10+
<meta-data
11+
android:name="com.google.android.gms.wallet.api.enabled"
12+
android:value="true" />
13+
</application>
14+
```
15+
16+
becomes
17+
18+
```json
19+
{
20+
"android": {
21+
"metaData": [
22+
{
23+
"android:name": "com.google.android.gms.wallet.api.enabled",
24+
"android:value": "true"
25+
}
26+
]
27+
}
28+
}
29+
```
30+
31+
<details>
32+
<summary>History</summary>
33+
34+
- [[4.2.0](https://github.com/microsoft/react-native-test-app/releases/tag/4.2.0)]
35+
Added
36+
37+
</details>

schema.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,22 @@
326326
}
327327
}
328328
}
329+
},
330+
"metaData": {
331+
"description": "A name-value pair for an item of additional, arbitrary data that can be supplied to the application.",
332+
"markdownDescription": "A name-value pair for an item of additional, arbitrary data that can be supplied to the application.\n\nEquivalent to\n[`<meta-data>`](https://developer.android.com/guide/topics/manifest/meta-data-element).\n\nExample:\n\n```xml\n<application>\n <meta-data\n android:name=\"com.google.android.gms.wallet.api.enabled\"\n android:value=\"true\" />\n</application>\n```\n\nbecomes\n\n```json\n{\n \"android\": {\n \"metaData\": [\n {\n \"android:name\": \"com.google.android.gms.wallet.api.enabled\",\n \"android:value\": \"true\"\n }\n ]\n }\n}\n```\n\n<details>\n<summary>History</summary>\n\n- [[4.2.0](https://github.com/microsoft/react-native-test-app/releases/tag/4.2.0)]\n Added\n\n</details>",
333+
"type": "array",
334+
"items": {
335+
"type": "object",
336+
"properties": {
337+
"android:name": {
338+
"type": "string"
339+
},
340+
"android:value": {
341+
"type": "string"
342+
}
343+
}
344+
}
329345
}
330346
}
331347
},

scripts/internal/generate-schema.mts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export async function readDocumentation(): Promise<Partial<Docs>> {
4242
"android.icons",
4343
"android.package",
4444
"android.permissions",
45+
"android.metaData",
4546
"android.signingConfigs",
4647
"android.versionCode",
4748
"ios.buildNumber",

scripts/schema.mjs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,18 @@ export function generateSchema(docs = {}) {
299299
},
300300
},
301301
},
302+
metaData: {
303+
description: extractBrief(docs["android.metaData"]),
304+
markdownDescription: docs["android.metaData"],
305+
type: "array",
306+
items: {
307+
type: "object",
308+
properties: {
309+
"android:name": { type: "string" },
310+
"android:value": { type: "string" },
311+
},
312+
},
313+
},
302314
},
303315
},
304316
ios: {

scripts/types.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,19 @@ export type AndroidConfig = {
1414
"android:name": string;
1515
"android:maxSdkVersion"?: string;
1616
}[];
17+
metaData?: {
18+
"android:name": string;
19+
"android:value": string;
20+
}[];
1721
};
1822
};
1923

2024
export type AndroidManifest = {
2125
"uses-feature": Record<string, string>[];
2226
"uses-permission": Record<string, string>[];
27+
application: {
28+
"meta-data": Record<string, string>[];
29+
};
2330
};
2431

2532
/************************
@@ -207,6 +214,7 @@ export type Docs = {
207214
"android.icons": string;
208215
"android.package": string;
209216
"android.permissions": string;
217+
"android.metaData": string;
210218
"android.signingConfigs": string;
211219
"android.versionCode": string;
212220
"ios.buildNumber": string;

0 commit comments

Comments
 (0)