use of com.android.aapt.Resources.XmlNode in project bundletool by google.
the class ResourceAnalyzerTest method transitive_compoundValue_style.
@Test
public void transitive_compoundValue_style() throws Exception {
// AndroidManifest
// --> 0x7f010001 (app_theme) --> 0x7f010002 (parent_theme) --> 0x7f020001 (string)
// |-> 0x7f020002 (string)
// |-> 0x7f020003 (string)
XmlNode manifest = AndroidManifest.create(xmlNode(xmlElement("manifest", xmlNode(xmlElement("application", xmlResourceReferenceAttribute(ANDROID_NAMESPACE_URI, "theme", /* attrResourceId= */
0x999999, /* valueResourceId= */
0x7f010001)))))).getManifestRoot().getProto();
ResourceTable resourceTable = resourceTable(pkg(0x7f, "com.test.app", type(0x01, "theme", entry(0x0001, "app_theme", compoundValueStyleWithResourceReferences(/* parentId= */
0x7f010002, /* referencedResourceIds= */
new int[] { 0x7f020002, 0x7f020003 })), entry(0x0002, "parent_theme", compoundValueStyleWithResourceReferences(/* parentId= */
null, /* referencedResourceIds= */
new int[] { 0x7f020001 }))), type(0x02, "string", entry(0x0001, "parent_theme_str", value("hello", DEFAULT_CONFIG)), entry(0x0002, "app_theme_str1", value("hello", DEFAULT_CONFIG)), entry(0x0003, "app_theme_str2", value("hello", DEFAULT_CONFIG)), entry(0x0099, "not_referenced", value("", DEFAULT_CONFIG)))));
AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.setManifest(manifest).setResourceTable(resourceTable)).build();
ImmutableSet<ResourceId> resourceIds = new ResourceAnalyzer(appBundle).findAllAppResourcesReachableFromBaseManifest();
assertThat(resourceIds).containsExactly(ResourceId.create(0x7f010001), ResourceId.create(0x7f010002), ResourceId.create(0x7f020001), ResourceId.create(0x7f020002), ResourceId.create(0x7f020003));
}
use of com.android.aapt.Resources.XmlNode in project bundletool by google.
the class ModuleSplitterTest method splitNameRemovedForInstalledSplit.
@Test
public void splitNameRemovedForInstalledSplit() throws Exception {
XmlNode manifest = androidManifest("com.test.app", withMainActivity("MainActivity"), withSplitNameActivity("FooActivity", "foo"));
BundleModule bundleModule = new BundleModuleBuilder("testModule").setManifest(manifest).build();
ImmutableList<ModuleSplit> moduleSplits = ModuleSplitter.createForTest(bundleModule, BUNDLETOOL_VERSION).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(2);
XmlElement activityElement = activities.get(1);
assertThat(activityElement.getAttributeList()).containsExactly(xmlAttribute(ANDROID_NAMESPACE_URI, "name", NAME_RESOURCE_ID, "FooActivity"));
}
use of com.android.aapt.Resources.XmlNode in project bundletool by google.
the class BundleModuleMergerTest method fuseApplicationElementsInManifest_1_8_0.
@Test
public void fuseApplicationElementsInManifest_1_8_0() throws Exception {
XmlNode installTimeModuleManifest = androidManifestForFeature("com.test.app.detail", withInstallTimeDelivery(), withSplitNameActivity("activity1", "detail"), withSplitNameService("service", "detail"));
createBasicZipBuilder(BUNDLE_CONFIG_1_8_0).addFileWithProtoContent(ZipPath.create("base/manifest/AndroidManifest.xml"), MANIFEST).addFileWithProtoContent(ZipPath.create("detail/manifest/AndroidManifest.xml"), installTimeModuleManifest).writeTo(bundleFile);
try (ZipFile appBundleZip = new ZipFile(bundleFile.toFile())) {
AppBundle appBundle = BundleModuleMerger.mergeNonRemovableInstallTimeModules(AppBundle.buildFromZip(appBundleZip), /* overrideBundleToolVersion = */
false);
XmlNode fusedManifest = androidManifest("com.test.app.detail", withSplitNameActivity("activity1", "detail"), withSplitNameService("service", "detail"), withMetadataValue("com.android.dynamic.apk.fused.modules", "base,detail"));
assertThat(appBundle.getBaseModule().getAndroidManifest().getManifestRoot().getProto()).isEqualTo(fusedManifest);
}
}
use of com.android.aapt.Resources.XmlNode in project bundletool by google.
the class BundleModuleMergerTest method testMultipleModulesWithInstallTime_implicitMergingDexRenaming.
@Test
public void testMultipleModulesWithInstallTime_implicitMergingDexRenaming() throws Exception {
XmlNode installTimeModuleManifest = androidManifestForFeature("com.test.app.detail", withInstallTimeDelivery());
createBasicZipBuilder(BUNDLE_CONFIG_1_0_0).addFileWithProtoContent(ZipPath.create("base/manifest/AndroidManifest.xml"), MANIFEST).addFileWithContent(ZipPath.create("base/dex/classes.dex"), DUMMY_CONTENT).addFileWithContent(ZipPath.create("base/assets/baseAssetfile.txt"), DUMMY_CONTENT).addFileWithProtoContent(ZipPath.create("detail/manifest/AndroidManifest.xml"), installTimeModuleManifest).addFileWithContent(ZipPath.create("detail/assets/detailsAssetfile.txt"), DUMMY_CONTENT).addFileWithContent(ZipPath.create("detail/dex/classes.dex"), DUMMY_CONTENT).writeTo(bundleFile);
try (ZipFile appBundleZip = new ZipFile(bundleFile.toFile())) {
AppBundle appBundlePreMerge = AppBundle.buildFromZip(appBundleZip);
AppBundle appBundlePostMerge = BundleModuleMerger.mergeNonRemovableInstallTimeModules(appBundlePreMerge, /* overrideBundleToolVersion = */
false);
assertThat(appBundlePostMerge.getModules().keySet().stream().map(BundleModuleName::getName)).containsExactly("base");
assertThat(appBundlePreMerge.getModules().values().stream().mapToLong(module -> module.getEntries().size()).sum()).isEqualTo(appBundlePostMerge.getModules().values().stream().mapToLong(module -> module.getEntries().size()).sum());
assertThat(appBundlePostMerge.getBaseModule().getEntry(ZipPath.create("dex/classes.dex"))).isPresent();
assertThat(appBundlePostMerge.getBaseModule().getEntry(ZipPath.create("dex/classes2.dex"))).isPresent();
}
}
use of com.android.aapt.Resources.XmlNode in project bundletool by google.
the class BundleModuleMergerTest method fuseOnlyActivitiesInManifest_1_0_0.
@Test
public void fuseOnlyActivitiesInManifest_1_0_0() throws Exception {
XmlNode installTimeModuleManifest = androidManifestForFeature("com.test.app.detail", withInstallTimeDelivery(), withSplitNameActivity("activity1", "detail"), withSplitNameService("service", "detail"));
createBasicZipBuilder(BUNDLE_CONFIG_1_0_0).addFileWithProtoContent(ZipPath.create("base/manifest/AndroidManifest.xml"), MANIFEST).addFileWithProtoContent(ZipPath.create("detail/manifest/AndroidManifest.xml"), installTimeModuleManifest).writeTo(bundleFile);
try (ZipFile appBundleZip = new ZipFile(bundleFile.toFile())) {
AppBundle appBundle = BundleModuleMerger.mergeNonRemovableInstallTimeModules(AppBundle.buildFromZip(appBundleZip), /* overrideBundleToolVersion = */
false);
XmlNode fusedManifest = androidManifest("com.test.app.detail", withSplitNameActivity("activity1", "detail"), withMetadataValue("com.android.dynamic.apk.fused.modules", "base,detail"));
assertThat(appBundle.getBaseModule().getAndroidManifest().getManifestRoot().getProto()).isEqualTo(fusedManifest);
}
}
Aggregations