Skip to content

Commit

Permalink
fix(android): strip xmlns definitions from child elements in AndroidM…
Browse files Browse the repository at this point in the history
…anifest.xml (#11462)

- TIMOB-27746: Apps built with 9.0.0 can't be uploaded to Firebase App Distribution when including certain modules.
  * Caused by "android-manifest.js" code's copyFromAndroidManfiest() function.
  * Node "xmldom" parser was wrongly injecting namespaces into chlid elements when doing a cloneNode() or importNode().
  * This is a bug in "xmldom" module. Worked-around it by stripping out namespace declarations via toString() function.
Co-authored-by: Gary Mathews <contact@garymathews.com>

Fixes TIMOB-27746
  • Loading branch information
jquick-axway authored Feb 5, 2020
1 parent 6a5664b commit 476ac79
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions android/cli/lib/android-manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,18 @@ class AndroidManifest {
toString() {
let text = '<?xml version="1.0" encoding="utf-8"?>' + os.EOL;
if (this._xmlDomDocument && this._xmlDomDocument.documentElement) {
// Write XML content to string.
text += this._xmlDomDocument.documentElement + os.EOL;

// Remove all "xmlns:android=<url>"" namespace definitions from child elements.
// Google only allows it in root <manifest/> element or else a build/validation error will occur.
let startReplaceIndex = text.indexOf('<manifest');
if (startReplaceIndex >= 0) {
startReplaceIndex = text.indexOf('>', startReplaceIndex);
text = text.replace(/\sxmlns:android=".*?"/g, (match, offset) => {
return (offset <= startReplaceIndex) ? match : '';
});
}
}
return text;
}
Expand Down Expand Up @@ -640,8 +651,8 @@ class AndroidManifest {
// Remove "xmlns:android" namespace attributes from all child elements. Only supported in <manifest/>.
// Note: CLI used to wrongly inject these after updating "tiapp.xml" if missing from root element.
const manifestEndIndex = text.indexOf('>', manifestIndex);
text = text.replace(/xmlns:android=".*?"/g, (match, p1) => {
return (p1 <= manifestEndIndex) ? match : '';
text = text.replace(/\sxmlns:android=".*?"/g, (match, offset) => {
return (offset <= manifestEndIndex) ? match : '';
});
}

Expand Down

0 comments on commit 476ac79

Please sign in to comment.