Search in sources :

Example 11 with XmlNode

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));
}
Also used : RawString(com.android.aapt.Resources.RawString) Value(com.android.aapt.Resources.Value) String(com.android.aapt.Resources.String) ManifestProtoUtils.androidManifest(com.android.tools.build.bundletool.testing.ManifestProtoUtils.androidManifest) RunWith(org.junit.runner.RunWith) Primitive(com.android.aapt.Resources.Primitive) AndroidManifest(com.android.tools.build.bundletool.model.AndroidManifest) ResourcesTableFactory.resourceTable(com.android.tools.build.bundletool.testing.ResourcesTableFactory.resourceTable) Symbol(com.android.aapt.Resources.Attribute.Symbol) ANDROID_NAMESPACE_URI(com.android.tools.build.bundletool.model.AndroidManifest.ANDROID_NAMESPACE_URI) ManifestProtoUtils.xmlCompiledItemAttribute(com.android.tools.build.bundletool.testing.ManifestProtoUtils.xmlCompiledItemAttribute) Item(com.android.aapt.Resources.Item) ResourceId(com.android.tools.build.bundletool.model.ResourceId) ImmutableList(com.google.common.collect.ImmutableList) Theories(org.junit.experimental.theories.Theories) ResourcesTableFactory.reference(com.android.tools.build.bundletool.testing.ResourcesTableFactory.reference) ResourcesTableFactory.entry(com.android.tools.build.bundletool.testing.ResourcesTableFactory.entry) Attribute(com.android.aapt.Resources.Attribute) ResourcesTableFactory.pkg(com.android.tools.build.bundletool.testing.ResourcesTableFactory.pkg) ResourcesTableFactory.type(com.android.tools.build.bundletool.testing.ResourcesTableFactory.type) ResourceTable(com.android.aapt.Resources.ResourceTable) Nullable(javax.annotation.Nullable) StyledString(com.android.aapt.Resources.StyledString) ManifestProtoUtils.xmlNode(com.android.tools.build.bundletool.testing.ManifestProtoUtils.xmlNode) ImmutableSet(com.google.common.collect.ImmutableSet) Style(com.android.aapt.Resources.Style) ResourcesTableFactory.value(com.android.tools.build.bundletool.testing.ResourcesTableFactory.value) ConfigValue(com.android.aapt.Resources.ConfigValue) Reference(com.android.aapt.Resources.Reference) Test(org.junit.Test) NO_NAMESPACE_URI(com.android.tools.build.bundletool.model.AndroidManifest.NO_NAMESPACE_URI) ManifestProtoUtils.xmlElement(com.android.tools.build.bundletool.testing.ManifestProtoUtils.xmlElement) Truth.assertThat(com.google.common.truth.Truth.assertThat) ResourcesTableFactory.fileReference(com.android.tools.build.bundletool.testing.ResourcesTableFactory.fileReference) CompoundValue(com.android.aapt.Resources.CompoundValue) Id(com.android.aapt.Resources.Id) FileReference(com.android.aapt.Resources.FileReference) AppBundleBuilder(com.android.tools.build.bundletool.testing.AppBundleBuilder) ManifestProtoUtils.xmlResourceReferenceAttribute(com.android.tools.build.bundletool.testing.ManifestProtoUtils.xmlResourceReferenceAttribute) XmlNode(com.android.aapt.Resources.XmlNode) AppBundle(com.android.tools.build.bundletool.model.AppBundle) Configuration(com.android.aapt.ConfigurationOuterClass.Configuration) XmlNode(com.android.aapt.Resources.XmlNode) AppBundle(com.android.tools.build.bundletool.model.AppBundle) ResourceId(com.android.tools.build.bundletool.model.ResourceId) AppBundleBuilder(com.android.tools.build.bundletool.testing.AppBundleBuilder) ResourceTable(com.android.aapt.Resources.ResourceTable) Test(org.junit.Test)

Example 12 with XmlNode

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"));
}
Also used : XmlNode(com.android.aapt.Resources.XmlNode) BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) XmlElement(com.android.aapt.Resources.XmlElement) BundleModule(com.android.tools.build.bundletool.model.BundleModule) Test(org.junit.Test)

Example 13 with XmlNode

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);
    }
}
Also used : XmlNode(com.android.aapt.Resources.XmlNode) AppBundle(com.android.tools.build.bundletool.model.AppBundle) ZipFile(java.util.zip.ZipFile) Test(org.junit.Test)

Example 14 with XmlNode

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();
    }
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) ManifestProtoUtils.withFeatureCondition(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withFeatureCondition) ManifestProtoUtils.withMetadataValue(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withMetadataValue) ManifestProtoUtils.withSplitNameActivity(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withSplitNameActivity) BundleModuleName(com.android.tools.build.bundletool.model.BundleModuleName) ZipPath(com.android.tools.build.bundletool.model.ZipPath) ManifestProtoUtils.androidManifest(com.android.tools.build.bundletool.testing.ManifestProtoUtils.androidManifest) BundleConfigBuilder(com.android.tools.build.bundletool.testing.BundleConfigBuilder) RunWith(org.junit.runner.RunWith) ZipBuilder(com.android.tools.build.bundletool.io.ZipBuilder) ManifestProtoUtils.androidManifestForAssetModule(com.android.tools.build.bundletool.testing.ManifestProtoUtils.androidManifestForAssetModule) ProtoTruth.assertThat(com.google.common.truth.extensions.proto.ProtoTruth.assertThat) ManifestProtoUtils.withOnDemandDelivery(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withOnDemandDelivery) ZipFile(java.util.zip.ZipFile) ManifestProtoUtils.androidManifestForMlModule(com.android.tools.build.bundletool.testing.ManifestProtoUtils.androidManifestForMlModule) ManifestProtoUtils.withSplitNameService(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withSplitNameService) Truth8.assertThat(com.google.common.truth.Truth8.assertThat) Path(java.nio.file.Path) Before(org.junit.Before) InvalidBundleException(com.android.tools.build.bundletool.model.exceptions.InvalidBundleException) TestData(com.android.tools.build.bundletool.TestData) FileOutputStream(java.io.FileOutputStream) Test(org.junit.Test) JUnit4(org.junit.runners.JUnit4) Truth.assertThat(com.google.common.truth.Truth.assertThat) Collectors(java.util.stream.Collectors) ManifestProtoUtils.withInstallTimeRemovableElement(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withInstallTimeRemovableElement) File(java.io.File) Correspondence(com.google.common.truth.Correspondence) ManifestProtoUtils.withMinSdkVersion(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withMinSdkVersion) Stream(java.util.stream.Stream) Rule(org.junit.Rule) XmlNode(com.android.aapt.Resources.XmlNode) BundleConfig(com.android.bundle.Config.BundleConfig) ManifestProtoUtils.withInstallTimeDelivery(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withInstallTimeDelivery) ManifestProtoUtils.androidManifestForFeature(com.android.tools.build.bundletool.testing.ManifestProtoUtils.androidManifestForFeature) AppBundle(com.android.tools.build.bundletool.model.AppBundle) TemporaryFolder(org.junit.rules.TemporaryFolder) XmlNode(com.android.aapt.Resources.XmlNode) AppBundle(com.android.tools.build.bundletool.model.AppBundle) BundleModuleName(com.android.tools.build.bundletool.model.BundleModuleName) ZipFile(java.util.zip.ZipFile) Test(org.junit.Test)

Example 15 with XmlNode

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);
    }
}
Also used : XmlNode(com.android.aapt.Resources.XmlNode) AppBundle(com.android.tools.build.bundletool.model.AppBundle) ZipFile(java.util.zip.ZipFile) Test(org.junit.Test)

Aggregations

XmlNode (com.android.aapt.Resources.XmlNode)99 Test (org.junit.Test)91 XmlElement (com.android.aapt.Resources.XmlElement)28 AppBundle (com.android.tools.build.bundletool.model.AppBundle)27 ManifestProtoUtils.androidManifest (com.android.tools.build.bundletool.testing.ManifestProtoUtils.androidManifest)23 Truth.assertThat (com.google.common.truth.Truth.assertThat)23 RunWith (org.junit.runner.RunWith)23 ResourceTable (com.android.aapt.Resources.ResourceTable)21 ImmutableList (com.google.common.collect.ImmutableList)21 AndroidManifest (com.android.tools.build.bundletool.model.AndroidManifest)16 Nullable (javax.annotation.Nullable)16 Theories (org.junit.experimental.theories.Theories)16 ZipFile (java.util.zip.ZipFile)12 FileReference (com.android.aapt.Resources.FileReference)10 AppBundleBuilder (com.android.tools.build.bundletool.testing.AppBundleBuilder)10 Configuration (com.android.aapt.ConfigurationOuterClass.Configuration)9 Attribute (com.android.aapt.Resources.Attribute)9 Symbol (com.android.aapt.Resources.Attribute.Symbol)9 CompoundValue (com.android.aapt.Resources.CompoundValue)9 ConfigValue (com.android.aapt.Resources.ConfigValue)9