Skip to content

Commit 9965d58

Browse files
authored
fix(cli): replace AndroidManifest.xml Cordova variables with default value (#3863)
1 parent 66f2efb commit 9965d58

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

cli/src/cordova.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Config } from './config';
2-
import { Plugin, PluginType, getAssets, getJSModules, getPlatformElement, getPluginPlatform, getPluginType, getPlugins, printPlugins } from './plugin';
2+
import { Plugin, PluginType, getAllElements, getAssets, getJSModules, getPlatformElement, getPluginPlatform, getPluginType, getPlugins, printPlugins } from './plugin';
33
import { copySync, ensureDirSync, readFileAsync, removeSync, writeFileAsync } from './util/fs';
44
import { basename, extname, join, resolve } from 'path';
55
import { buildXmlElement, installDeps, log, logError, logFatal, logInfo, logWarn, parseXML, readXML, resolveNode, writeXML } from './common';
@@ -381,9 +381,11 @@ export async function writeCordovaAndroidManifest(cordovaPlugins: Plugin[], conf
381381
let rootXMLEntries: Array<any> = [];
382382
let applicationXMLEntries: Array<any> = [];
383383
let applicationXMLAttributes: Array<any> = [];
384+
let prefsArray: Array<any> = [];
384385
cordovaPlugins.map(async p => {
385386
const editConfig = getPlatformElement(p, platform, 'edit-config');
386387
const configFile = getPlatformElement(p, platform, 'config-file');
388+
prefsArray = prefsArray.concat(getAllElements(p, platform, 'preference'));
387389
editConfig.concat(configFile).map(async (configElement: any) => {
388390
if (configElement.$ && (configElement.$.target && configElement.$.target.includes('AndroidManifest.xml') || configElement.$.file && configElement.$.file.includes('AndroidManifest.xml'))) {
389391
const keys = Object.keys(configElement).filter(k => k !== '$');
@@ -425,6 +427,9 @@ ${applicationXMLEntries.join('\n')}
425427
${rootXMLEntries.join('\n')}
426428
</manifest>`;
427429
content = content.replace(new RegExp(('$PACKAGE_NAME').replace('$', '\\$&'), 'g'), '${applicationId}');
430+
prefsArray.map((preference: any) => {
431+
content = content.replace(new RegExp(('$' + preference.$.name).replace('$', '\\$&'), 'g'), preference.$.default);
432+
});
428433
if (existsSync(manifestPath)) {
429434
await writeFileAsync(manifestPath, content);
430435
}

0 commit comments

Comments
 (0)