use of com.android.tools.build.bundletool.model.ManifestEditor in project bundletool by google.
the class ModuleSplitter method makeInstantManifestChanges.
/**
* Updates the split to insert instant app specific manifest changes:
*
* <ul>
* <li>Sets the targetSandboxVersion to 2.
* <li>Sets the minSdkVersion to 21 if it the minSdkVersion is lower than 21.
* <li>Removes any known splits from the base manifest, which may contain on demand split
* information.
* </ul>
*/
public ModuleSplit makeInstantManifestChanges(ModuleSplit moduleSplit) {
AndroidManifest manifest = moduleSplit.getAndroidManifest();
ManifestEditor editor = manifest.toEditor();
editor.setTargetSandboxVersion(2);
if (manifest.getEffectiveMinSdkVersion() < 21) {
editor.setMinSdkVersion(21);
}
editor.removeUnknownSplitComponents(allModuleNames);
return moduleSplit.toBuilder().setAndroidManifest(editor.save()).build();
}
use of com.android.tools.build.bundletool.model.ManifestEditor in project bundletool by google.
the class FusingAndroidManifestMerger method mergeManifests.
private AndroidManifest mergeManifests(AndroidManifest baseManifest, List<AndroidManifest> featureManifests) {
// Gather all child elements of 'application' from all manifest. If element with the same name
// and type is presented in more than one manifest we give precedency to one in feature module.
// All feature manifests are sorted by feature module name in this method.
ImmutableListMultimap<ApplicationElementId, XmlProtoElement> applicationElements = gatherApplicationElementsManifests(ImmutableList.<AndroidManifest>builder().addAll(featureManifests).add(baseManifest).build(), elementsToMerge);
// This is optimization that allows to skip merging if there is no mergeable elements in
// feature modules.
long numberOfMergeableElementsInBase = baseManifest.getManifestRoot().getElement().getChildrenElements(AndroidManifest.APPLICATION_ELEMENT_NAME).flatMap(application -> application.getChildrenElements()).filter(element -> elementsToMerge.contains(element.getName())).count();
if (numberOfMergeableElementsInBase == applicationElements.size()) {
return baseManifest;
}
// Merge manifest elements with the same name and type based on specified mode.
ImmutableMap<ApplicationElementId, XmlProtoElement> mergedElements = applicationElements.keySet().stream().collect(toImmutableMap(Function.identity(), key -> mergeElements(key, applicationElements.get(key))));
ManifestEditor manifestEditor = baseManifest.toEditor();
XmlProtoElementBuilder applicationElement = manifestEditor.getRawProto().getOrCreateChildElement(AndroidManifest.APPLICATION_ELEMENT_NAME);
// Replace original elements from the base manifest with merged ones. This is done in a way to
// preserve original elements ordering and additional elements are added to the end.
Set<XmlProtoElement> replacedElements = Sets.newIdentityHashSet();
applicationElement.modifyChildElements(child -> stream(getCorrespondingElementFromMergedElements(child, mergedElements)).peek(replacedElements::add).map(element -> XmlProtoNodeBuilder.createElementNode(element.toBuilder())).collect(toOptional()).orElse(child));
mergedElements.values().stream().filter(not(replacedElements::contains)).forEach(element -> applicationElement.addChildElement(element.toBuilder()));
return manifestEditor.save();
}
use of com.android.tools.build.bundletool.model.ManifestEditor in project bundletool by google.
the class ArchivedAndroidManifestUtils method createArchivedManifest.
public static AndroidManifest createArchivedManifest(AndroidManifest manifest) {
checkNotNull(manifest);
ManifestEditor editor = new ManifestEditor(createMinimalManifestTag(), BundleToolVersion.getCurrentVersion()).setPackage(manifest.getPackageName()).addMetaDataBoolean(META_DATA_KEY_ARCHIVED, true);
manifest.getVersionCode().ifPresent(editor::setVersionCode);
manifest.getVersionName().ifPresent(editor::setVersionName);
manifest.getSharedUserId().ifPresent(editor::setSharedUserId);
manifest.getSharedUserLabel().ifPresent(editor::setSharedUserLabel);
manifest.getMinSdkVersion().ifPresent(editor::setMinSdkVersion);
manifest.getMaxSdkVersion().ifPresent(editor::setMaxSdkVersion);
manifest.getTargetSdkVersion().ifPresent(editor::setTargetSdkVersion);
if (manifest.hasApplicationElement()) {
manifest.getDescription().ifPresent(editor::setDescription);
manifest.getHasFragileUserData().ifPresent(editor::setHasFragileUserData);
manifest.getIsGame().ifPresent(editor::setIsGame);
manifest.getIcon().ifPresent(editor::setIcon);
if (manifest.hasLabelString()) {
manifest.getLabelString().ifPresent(editor::setLabelAsString);
}
if (manifest.hasLabelRefId()) {
manifest.getLabelRefId().ifPresent(editor::setLabelAsRefId);
}
getArchivedAllowBackup(manifest).ifPresent(editor::setAllowBackup);
manifest.getFullBackupOnly().ifPresent(editor::setFullBackupOnly);
manifest.getFullBackupContent().ifPresent(editor::setFullBackupContent);
manifest.getDataExtractionRules().ifPresent(editor::setDataExtractionRules);
}
editor.copyPermissions(manifest);
editor.copyPermissionGroups(manifest);
editor.addActivity(createReactivateActivity());
editor.addReceiver(createUpdateBroadcastReceiver());
return editor.save();
}
Aggregations