Search in sources :

Example 41 with AndroidManifest

use of com.android.tools.build.bundletool.model.AndroidManifest in project bundletool by google.

the class ResourceAnalyzerTest method customManifest_filteredRefs_resolved.

@Test
public void customManifest_filteredRefs_resolved() throws Exception {
    XmlNode baseManifest = AndroidManifest.create(xmlNode(xmlElement("manifest", xmlNode(xmlElement("application", ImmutableList.of(xmlResourceReferenceAttribute(ANDROID_NAMESPACE_URI, "name", /* attrResourceId= */
    0x999998, /* valueResourceId= */
    0x87654321), xmlResourceReferenceAttribute(ANDROID_NAMESPACE_URI, "name2", /* attrResourceId= */
    0x999999, /* valueResourceId= */
    0x12345678))))))).getManifestRoot().getProto();
    AndroidManifest customManifest = AndroidManifest.create(xmlNode(xmlElement("manifest", xmlNode(xmlElement("application", xmlResourceReferenceAttribute(ANDROID_NAMESPACE_URI, "name2", /* attrResourceId= */
    0x999999, /* valueResourceId= */
    0x12345678))))));
    ResourceTable resourceTable = resourceTable(pkg(0x12, "com.test.app", type(0x34, "string", entry(0x5678, "name", value("hello", DEFAULT_CONFIG)))), pkg(0x87, "com.test.app", type(0x65, "string", entry(0x4321, "name2", value("world", DEFAULT_CONFIG)))));
    AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.setManifest(baseManifest).setResourceTable(resourceTable)).build();
    ImmutableSet<ResourceId> resourceIds = new ResourceAnalyzer(appBundle).findAllAppResourcesReachableFromManifest(customManifest);
    assertThat(resourceIds).containsExactly(ResourceId.create(0x12345678));
}
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) AndroidManifest(com.android.tools.build.bundletool.model.AndroidManifest) ResourceTable(com.android.aapt.Resources.ResourceTable) Test(org.junit.Test)

Example 42 with AndroidManifest

use of com.android.tools.build.bundletool.model.AndroidManifest 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 43 with AndroidManifest

use of com.android.tools.build.bundletool.model.AndroidManifest in project bundletool by google.

the class FusingAndroidManifestMergerTest method mergeChildrenMode_metadataWithoutName_notMerged.

@Test
public void mergeChildrenMode_metadataWithoutName_notMerged() {
    SetMultimap<BundleModuleName, AndroidManifest> manifests = createManifests(androidManifest("com.testapp", withActivity("myActivity", activity -> activity.addChildElement(XmlProtoElementBuilder.create("meta-data").addChildElement(XmlProtoElementBuilder.create("data"))))), androidManifestForFeature("com.testapp.feature", withActivity("myActivity", activity -> activity.addChildElement(XmlProtoElementBuilder.create("meta-data").addChildElement(XmlProtoElementBuilder.create("action"))))));
    AndroidManifest merged = createMerger(Mode.MERGE_CHILDREN).merge(manifests);
    AndroidManifest expected = AndroidManifest.create(androidManifest("com.testapp", withActivity("myActivity", activity -> activity.addChildElement(XmlProtoElementBuilder.create("meta-data").addChildElement(XmlProtoElementBuilder.create("action"))))));
    assertThat(merged).isEqualTo(expected);
}
Also used : BundleModuleName(com.android.tools.build.bundletool.model.BundleModuleName) AndroidManifest(com.android.tools.build.bundletool.model.AndroidManifest) Test(org.junit.Test)

Example 44 with AndroidManifest

use of com.android.tools.build.bundletool.model.AndroidManifest in project bundletool by google.

the class FusingAndroidManifestMergerTest method mergeFeatureElementsIntoBaseManifest.

@Test
@Theory
public void mergeFeatureElementsIntoBaseManifest(FusingAndroidManifestMerger.Mode mode) {
    SetMultimap<BundleModuleName, AndroidManifest> manifests = createManifests(androidManifest("com.testapp", withSplitNameService("onlyBaseService", "base"), withSplitNameService("baseAndFeatureService", "base"), withSplitNameActivity("myActivity", "base")), androidManifestForFeature("com.testapp.feature1", withSplitNameService("baseAndFeatureService", "feature1"), withSplitNameActivity("anotherActivity", "feature1")), androidManifestForFeature("com.testapp.feature2", withSplitNameService("justFeatureService", "feature2"), withSplitNameActivity("myActivity", "feature2")));
    AndroidManifest merged = createMerger(mode).merge(manifests);
    AndroidManifest expected = AndroidManifest.create(androidManifest("com.testapp", withSplitNameService("onlyBaseService", "base"), withSplitNameService("baseAndFeatureService", "feature1"), withSplitNameActivity("myActivity", "feature2"), withSplitNameActivity("anotherActivity", "feature1"), withSplitNameService("justFeatureService", "feature2")));
    assertThat(merged).isEqualTo(expected);
}
Also used : BundleModuleName(com.android.tools.build.bundletool.model.BundleModuleName) AndroidManifest(com.android.tools.build.bundletool.model.AndroidManifest) Test(org.junit.Test) Theory(org.junit.experimental.theories.Theory)

Example 45 with AndroidManifest

use of com.android.tools.build.bundletool.model.AndroidManifest in project bundletool by google.

the class ModuleSplitsToShardMergerTest method manifests_valid_takeManifestOfTheBase_versionBefore_0_13_4.

@Test
public void manifests_valid_takeManifestOfTheBase_versionBefore_0_13_4() throws Exception {
    TestComponent.useTestModule(this, TestModule.builder().withBundletoolVersion("0.13.3").build());
    AndroidManifest manifestBase = AndroidManifest.create(androidManifest("com.test.app1", withCustomThemeActivity("activity1", 1), withCustomThemeActivity("activity2", 2)));
    AndroidManifest manifestFeat = AndroidManifest.create(androidManifest("com.test.app2", withCustomThemeActivity("activity1", 3)));
    ModuleSplit split1 = createModuleSplitBuilder().setAndroidManifest(manifestBase).setModuleName(BundleModuleName.create("base")).build();
    ModuleSplit split2 = createModuleSplitBuilder().setAndroidManifest(manifestFeat).setModuleName(BundleModuleName.create("module")).build();
    ModuleSplit shard = splitsToShardMerger.mergeSingleShard(ImmutableList.of(split1, split2), createCache());
    assertThat(shard.getAndroidManifest().getPackageName()).isEqualTo("com.test.app1");
    assertThat(extractActivityThemeRefIds(shard.getAndroidManifest())).containsExactly("activity1", 1, "activity2", 2);
}
Also used : ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) AndroidManifest(com.android.tools.build.bundletool.model.AndroidManifest) Test(org.junit.Test)

Aggregations

AndroidManifest (com.android.tools.build.bundletool.model.AndroidManifest)130 Test (org.junit.Test)115 ImmutableList (com.google.common.collect.ImmutableList)94 AppBundleBuilder (com.android.tools.build.bundletool.testing.AppBundleBuilder)90 ManifestProtoUtils.androidManifest (com.android.tools.build.bundletool.testing.ManifestProtoUtils.androidManifest)89 Truth.assertThat (com.google.common.truth.Truth.assertThat)89 RunWith (org.junit.runner.RunWith)89 ImmutableSet (com.google.common.collect.ImmutableSet)87 AppBundle (com.android.tools.build.bundletool.model.AppBundle)84 ApkTargeting (com.android.bundle.Targeting.ApkTargeting)82 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)81 VariantTargeting (com.android.bundle.Targeting.VariantTargeting)80 ZipPath (com.android.tools.build.bundletool.model.ZipPath)80 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)79 ImmutableSet.toImmutableSet (com.google.common.collect.ImmutableSet.toImmutableSet)79 Path (java.nio.file.Path)79 AppBundleSerializer (com.android.tools.build.bundletool.io.AppBundleSerializer)78 Files (java.nio.file.Files)78 Before (org.junit.Before)78 Rule (org.junit.Rule)78