use of com.android.aapt.Resources.XmlNode in project bundletool by google.
the class ModuleSplitterTest method nonInstantActivityRemovedForInstantManifest.
@Test
public void nonInstantActivityRemovedForInstantManifest() throws Exception {
XmlNode manifest = androidManifest("com.test.app", withMainActivity("MainActivity"), withSplitNameActivity("FooActivity", "onDemandModule"));
BundleModule bundleModule = new BundleModuleBuilder("onDemandModule").setManifest(manifest).build();
ImmutableList<ModuleSplit> moduleSplits = ModuleSplitter.createNoStamp(bundleModule, BUNDLETOOL_VERSION, APP_BUNDLE, ApkGenerationConfiguration.builder().setForInstantAppVariants(true).build(), lPlusVariantTargeting(), ImmutableSet.of()).splitModule();
assertThat(moduleSplits).hasSize(1);
ModuleSplit masterSplit = moduleSplits.get(0);
ImmutableList<XmlElement> activities = masterSplit.getAndroidManifest().getManifestRoot().getElement().getChildElement("application").getChildrenElements(ACTIVITY_ELEMENT_NAME).map(XmlProtoElement::getProto).collect(toImmutableList());
assertThat(activities).hasSize(1);
XmlElement activityElement = activities.get(0);
assertThat(activityElement.getAttributeList()).containsExactly(xmlAttribute(ANDROID_NAMESPACE_URI, "name", NAME_RESOURCE_ID, "MainActivity"));
}
use of com.android.aapt.Resources.XmlNode in project bundletool by google.
the class ManifestProtoUtils method androidManifestForAssetModule.
public static XmlNode androidManifestForAssetModule(String packageName, ManifestMutator... manifestMutators) {
XmlNode manifestNode = xmlNode(xmlElement("manifest", ImmutableList.of(xmlNamespace("android", ANDROID_NAMESPACE_URI)), ImmutableList.of(xmlAttribute("package", packageName))));
XmlProtoNodeBuilder xmlProtoNode = new XmlProtoNode(manifestNode).toBuilder();
// Default mutators
withTypeAttribute(MODULE_TYPE_ASSET_VALUE).accept(xmlProtoNode.getElement());
withFusingAttribute(true).accept(xmlProtoNode.getElement());
// Additional mutators and overrides of defaults.
for (ManifestMutator manifestMutator : manifestMutators) {
manifestMutator.accept(xmlProtoNode.getElement());
}
// Set a delivery mode if none was set.
if (!AndroidManifest.create(xmlProtoNode.build().getProto()).isDeliveryTypeDeclared()) {
withOnDemandDelivery().accept(xmlProtoNode.getElement());
}
return xmlProtoNode.build().getProto();
}
use of com.android.aapt.Resources.XmlNode in project bundletool by google.
the class ManifestProtoUtils method androidManifest.
/**
* Creates an Android Manifest.
*
* <p>Without providing any {@code manifestMutator} creates a minimal valid manifest.
*/
public static XmlNode androidManifest(String packageName, ManifestMutator... manifestMutators) {
XmlNode manifestNode = xmlNode(xmlElement("manifest", ImmutableList.of(xmlNamespace("android", ANDROID_NAMESPACE_URI)), ImmutableList.of(xmlAttribute("package", packageName), xmlDecimalIntegerAttribute(ANDROID_NAMESPACE_URI, "versionCode", 0x0101021b, 1))));
XmlProtoNodeBuilder xmlProtoNode = new XmlProtoNode(manifestNode).toBuilder();
withHasCode(false).accept(xmlProtoNode.getElement());
for (ManifestMutator manifestMutator : manifestMutators) {
manifestMutator.accept(xmlProtoNode.getElement());
}
return xmlProtoNode.build().getProto();
}
use of com.android.aapt.Resources.XmlNode in project bundletool by google.
the class ResourceAnalyzerTest method transitive_item_xmlFileWithResourceReference.
@Test
public void transitive_item_xmlFileWithResourceReference() throws Exception {
// AndroidManifest --> 0x7f010001 (xml file) --> 0x7f020002 (string)
XmlNode manifest = AndroidManifest.create(xmlNode(xmlElement("manifest", xmlNode(xmlElement("application", xmlResourceReferenceAttribute(NO_NAMESPACE_URI, "attr_pointing_to_xml", /* attrResourceId= */
0x999999, /* valueResourceId= */
0x7f010001)))))).getManifestRoot().getProto();
XmlNode embeddedXmlFile = AndroidManifest.create(xmlNode(xmlElement("root", xmlResourceReferenceAttribute(ANDROID_NAMESPACE_URI, "name", /* attrResourceId= */
0x999999, /* valueResourceId= */
0x7f020002)))).getManifestRoot().getProto();
ResourceTable resourceTable = resourceTable(pkg(0x7f, "com.test.app", type(0x01, "file", entry(0x0001, "xml_file", fileReference("res/xml/embedded.xml", FileReference.Type.PROTO_XML, DEFAULT_CONFIG))), type(0x02, "string", entry(0x0002, "name_str", value("hello", DEFAULT_CONFIG)), entry(0x0099, "not_referenced", value("", DEFAULT_CONFIG)))));
AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.setManifest(manifest).setResourceTable(resourceTable).addFile("res/xml/embedded.xml", embeddedXmlFile.toByteArray())).build();
ImmutableSet<ResourceId> resourceIds = new ResourceAnalyzer(appBundle).findAllAppResourcesReachableFromBaseManifest();
assertThat(resourceIds).containsExactly(ResourceId.create(0x7f010001), ResourceId.create(0x7f020002));
}
Aggregations