Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(android): improved merge of <uses-feature/> elements #11110

Merged
merged 1 commit into from
Aug 20, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 30 additions & 3 deletions android/cli/lib/AndroidManifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -513,12 +513,39 @@ function AndroidManifest(filename) {
case 'uses-feature':
this[tag] || (this[tag] = []);
src[tag].forEach(function (tagItem) {
// Check for already added features.
let duplicateItem = this[tag].find(function (nextItem) {
// If given "uses-feature" name has already been added, then fetch its object.
const duplicateItem = this[tag].find(function (nextItem) {
// Compare them directly or by name.
return (nextItem === tagItem) || (nextItem.name === tagItem.name);
});
if (!duplicateItem) {
if (duplicateItem === tagItem) {
// Given reference was already added. Do nothing.
} else if (duplicateItem) {
// This is a duplicate "uses-feature" element name. Merge its settings.
if (typeof tagItem['tools:replace'] === 'string') {
// This attribute provides an array of other attributes that must be replaced.
tagItem['tools:replace'].split(',').forEach(function (attributeName) {
attributeName = attributeName.replace(androidAttrPrefixRegExp, '');
if (attributeName !== 'name') {
const value = tagItem[attributeName];
if (typeof value === 'undefined') {
delete duplicateItem[attributeName];
} else {
duplicateItem[attributeName] = value;
}
}
});
} else if (duplicateItem.required === false) {
// Do a logical OR on the "required" attribute value.
// If the "required" attribute is not defined, then it is considered true.
if (typeof tagItem.required === 'undefined') {
delete duplicateItem.required;
} else if (tagItem.required) {
duplicateItem.required = tagItem.required;
}
}
} else {
// The given "uses-feature" name has not been added yet. Do so now.
this[tag].push(tagItem);
}
}, this);
Expand Down