Search in sources :

Example 6 with SplitsProtoXmlBuilder

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

the class SplitsXmlInjectorTest method process.

@Test
public void process() throws Exception {
    ModuleSplit baseMasterSplit = createModuleSplit(BASE_MODULE_NAME.getName(), /* splitId= */
    "", /* masterSplit= */
    true, SPLIT, /* languageTargeting= */
    null);
    ImmutableList<ModuleSplit> otherSplits = ImmutableList.of(createModuleSplit(BASE_MODULE_NAME.getName(), /* splitId= */
    "config.ru", /* masterSplit= */
    false, SPLIT, languageTargeting("ru")), createModuleSplit(BASE_MODULE_NAME.getName(), /* splitId= */
    "config.fr", /* masterSplit= */
    false, SPLIT, languageTargeting("fr")), createModuleSplit("module", /* splitId= */
    "module", /* masterSplit= */
    true, SPLIT, /* languageTargeting= */
    null), createModuleSplit("module", /* splitId= */
    "module.config.ru", /* masterSplit= */
    false, SPLIT, languageTargeting("ru")));
    GeneratedApks generatedApks = GeneratedApks.fromModuleSplits(ImmutableList.<ModuleSplit>builder().add(baseMasterSplit).addAll(otherSplits).build());
    assertThat(generatedApks.getAllApksStream()).containsAtLeastElementsIn(otherSplits);
    ModuleSplit processedBaseMasterSplit = xmlInjectorProcess(generatedApks).stream().filter(module -> module.isMasterSplit() && module.isBaseModuleSplit()).collect(onlyElement());
    assertThat(processedBaseMasterSplit.getAndroidManifest().getMetadataResourceId("com.android.vending.splits")).hasValue(0x7f010000);
    assertThat(processedBaseMasterSplit.getResourceTable().get()).containsResource("com.example.app:xml/splits0").withFileReference("res/xml/splits0.xml");
    XmlNode expectedSplitsProtoXml = new SplitsProtoXmlBuilder().addLanguageMapping(BundleModuleName.create("module"), "ru", "module.config.ru").addLanguageMapping(BASE_MODULE_NAME, "ru", "config.ru").addLanguageMapping(BASE_MODULE_NAME, "fr", "config.fr").build();
    assertThat(XmlNode.parseFrom(processedBaseMasterSplit.getEntries().get(0).getContent().read())).ignoringRepeatedFieldOrder().isEqualTo(expectedSplitsProtoXml);
}
Also used : ARCHIVE(com.android.tools.build.bundletool.model.ModuleSplit.SplitType.ARCHIVE) ApkTargeting(com.android.bundle.Targeting.ApkTargeting) BundleModuleName(com.android.tools.build.bundletool.model.BundleModuleName) ManifestProtoUtils.androidManifest(com.android.tools.build.bundletool.testing.ManifestProtoUtils.androidManifest) RunWith(org.junit.runner.RunWith) AndroidManifest(com.android.tools.build.bundletool.model.AndroidManifest) BASE_MODULE_NAME(com.android.tools.build.bundletool.model.BundleModuleName.BASE_MODULE_NAME) MoreCollectors.onlyElement(com.google.common.collect.MoreCollectors.onlyElement) TruthResourceTable.assertThat(com.android.tools.build.bundletool.testing.truth.resources.TruthResourceTable.assertThat) ProtoTruth.assertThat(com.google.common.truth.extensions.proto.ProtoTruth.assertThat) ImmutableList(com.google.common.collect.ImmutableList) ResourceTableBuilder(com.android.tools.build.bundletool.testing.ResourceTableBuilder) Theories(org.junit.experimental.theories.Theories) TargetingUtils.languageTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.languageTargeting) SYSTEM(com.android.tools.build.bundletool.model.ModuleSplit.SplitType.SYSTEM) STANDALONE(com.android.tools.build.bundletool.model.ModuleSplit.SplitType.STANDALONE) Truth8.assertThat(com.google.common.truth.Truth8.assertThat) ResourceTable(com.android.aapt.Resources.ResourceTable) VariantTargeting(com.android.bundle.Targeting.VariantTargeting) Nullable(javax.annotation.Nullable) Before(org.junit.Before) INSTANT(com.android.tools.build.bundletool.model.ModuleSplit.SplitType.INSTANT) ImmutableMap(com.google.common.collect.ImmutableMap) TestUtils.createModuleEntryForFile(com.android.tools.build.bundletool.testing.TestUtils.createModuleEntryForFile) UTF_8(java.nio.charset.StandardCharsets.UTF_8) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Collection(java.util.Collection) SplitsProtoXmlBuilder(com.android.tools.build.bundletool.model.SplitsProtoXmlBuilder) Test(org.junit.Test) Truth.assertThat(com.google.common.truth.Truth.assertThat) LanguageTargeting(com.android.bundle.Targeting.LanguageTargeting) SplitType(com.android.tools.build.bundletool.model.ModuleSplit.SplitType) GeneratedApks(com.android.tools.build.bundletool.model.GeneratedApks) XmlNode(com.android.aapt.Resources.XmlNode) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) ModuleEntry(com.android.tools.build.bundletool.model.ModuleEntry) ExtensionRegistry(com.google.protobuf.ExtensionRegistry) Optional(java.util.Optional) SPLIT(com.android.tools.build.bundletool.model.ModuleSplit.SplitType.SPLIT) XmlNode(com.android.aapt.Resources.XmlNode) GeneratedApks(com.android.tools.build.bundletool.model.GeneratedApks) SplitsProtoXmlBuilder(com.android.tools.build.bundletool.model.SplitsProtoXmlBuilder) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) Test(org.junit.Test)

Aggregations

SplitsProtoXmlBuilder (com.android.tools.build.bundletool.model.SplitsProtoXmlBuilder)6 ResourceTable (com.android.aapt.Resources.ResourceTable)4 XmlNode (com.android.aapt.Resources.XmlNode)4 GeneratedApks (com.android.tools.build.bundletool.model.GeneratedApks)4 ModuleSplit (com.android.tools.build.bundletool.model.ModuleSplit)4 ResourceTableBuilder (com.android.tools.build.bundletool.testing.ResourceTableBuilder)4 Test (org.junit.Test)4 ApkTargeting (com.android.bundle.Targeting.ApkTargeting)3 LanguageTargeting (com.android.bundle.Targeting.LanguageTargeting)3 VariantTargeting (com.android.bundle.Targeting.VariantTargeting)3 AndroidManifest (com.android.tools.build.bundletool.model.AndroidManifest)3 BundleModuleName (com.android.tools.build.bundletool.model.BundleModuleName)3 BASE_MODULE_NAME (com.android.tools.build.bundletool.model.BundleModuleName.BASE_MODULE_NAME)3 ModuleEntry (com.android.tools.build.bundletool.model.ModuleEntry)3 SplitType (com.android.tools.build.bundletool.model.ModuleSplit.SplitType)3 ARCHIVE (com.android.tools.build.bundletool.model.ModuleSplit.SplitType.ARCHIVE)3 INSTANT (com.android.tools.build.bundletool.model.ModuleSplit.SplitType.INSTANT)3 SPLIT (com.android.tools.build.bundletool.model.ModuleSplit.SplitType.SPLIT)3 STANDALONE (com.android.tools.build.bundletool.model.ModuleSplit.SplitType.STANDALONE)3 SYSTEM (com.android.tools.build.bundletool.model.ModuleSplit.SplitType.SYSTEM)3