-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
46 lines (37 loc) · 1.48 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
const { AndroidConfig, withAndroidManifest, withDangerousMod } = require('expo/config-plugins');
const { mkdir, copyFile } = require('fs/promises');
const { join } = require('path');
/**
* Android network security config
*
* @param {import('@expo/config-types').ExpoConfig} config
* @param {{networkSecurityConfig: string, enable?: boolean}} options
* @returns {import('@expo/config-types').ExpoConfig} config
*/
module.exports = function withExpoNetworkSecurityConfig(config, { enable, networkSecurityConfig }) {
// Early return switch
if (!enable) return config;
const { getMainApplicationOrThrow } = AndroidConfig.Manifest;
const { getResourceFolderAsync } = AndroidConfig.Paths;
// Copy network_security_config.xml to android/app/src/main/res/xml
withDangerousMod(config, [
'android',
async (config) => {
const { projectRoot } = config.modRequest;
const resourcePath = await getResourceFolderAsync(projectRoot);
await mkdir(join(resourcePath, '/xml'), { recursive: true });
await copyFile(
join(projectRoot, networkSecurityConfig),
join(resourcePath, '/xml/network_security_config.xml'),
);
return config;
},
]);
// Add networkSecurityConfig to AndroidManifest.xml
withAndroidManifest(config, (config) => {
const mainApplication = getMainApplicationOrThrow(config.modResults);
mainApplication.$['android:networkSecurityConfig'] = '@xml/network_security_config';
return config;
});
return config;
};