fix(android): write network_security_config.xml to res/xml

walk() only matches files, so ensureNetworkSecurityXml never found
app/src/main/res and skipped creating the XML. AndroidManifest still
referenced @xml/network_security_config, causing AAPT link failures.

Co-authored-by: ShuMengya <shumengya666@outlook.com>
This commit is contained in:
Cursor Agent
2026-06-06 06:08:26 +00:00
parent c55aaf8f30
commit 475face0d3

View File

@@ -112,18 +112,19 @@ const NETWORK_SECURITY_XML = `<?xml version="1.0" encoding="utf-8"?>
`; `;
function ensureNetworkSecurityXml(androidRoot) { function ensureNetworkSecurityXml(androidRoot) {
const resDirs = walk(androidRoot, (p) => { const resDir = path.join(androidRoot, "app", "src", "main", "res");
const normalized = p.replace(/\\/g, "/"); if (!fs.existsSync(resDir)) {
return normalized.endsWith("/app/src/main/res"); console.warn(
}); `No Android res directory found for network_security_config.xml: ${resDir}`,
);
for (const resDir of resDirs) { return;
const xmlDir = path.join(resDir, "xml");
fs.mkdirSync(xmlDir, { recursive: true });
const target = path.join(xmlDir, "network_security_config.xml");
fs.writeFileSync(target, NETWORK_SECURITY_XML);
console.log(`Wrote ${path.relative(root, target)}`);
} }
const xmlDir = path.join(resDir, "xml");
fs.mkdirSync(xmlDir, { recursive: true });
const target = path.join(xmlDir, "network_security_config.xml");
fs.writeFileSync(target, NETWORK_SECURITY_XML);
console.log(`Wrote ${path.relative(root, target)}`);
} }
function patchAndroidManifest(androidRoot) { function patchAndroidManifest(androidRoot) {