use of com.android.tools.build.bundletool.model.SplitsProtoXmlBuilder in project bundletool by google.
the class SplitsXmlInjector method processStandaloneVariant.
private static ModuleSplit processStandaloneVariant(ModuleSplit split) {
if (!split.getResourceTable().isPresent()) {
return split;
}
SplitsProtoXmlBuilder splitsProtoXmlBuilder = new SplitsProtoXmlBuilder();
addLanguageSplitsFromResourceTable(splitsProtoXmlBuilder, split);
return injectSplitsXml(split, splitsProtoXmlBuilder.build());
}
use of com.android.tools.build.bundletool.model.SplitsProtoXmlBuilder in project bundletool by google.
the class SplitsXmlInjector method getSplitsXmlContentFromResourceTables.
private static XmlNode getSplitsXmlContentFromResourceTables(Collection<ModuleSplit> splits) {
SplitsProtoXmlBuilder splitsProtoXmlBuilder = new SplitsProtoXmlBuilder();
splits.stream().filter(ModuleSplit::isMasterSplit).forEach(split -> addLanguageSplitsFromResourceTable(splitsProtoXmlBuilder, split));
return splitsProtoXmlBuilder.build();
}
use of com.android.tools.build.bundletool.model.SplitsProtoXmlBuilder in project bundletool by google.
the class SplitsXmlInjectorTest method process_standaloneSplitTypes.
@Test
public void process_standaloneSplitTypes() throws Exception {
ModuleSplit standalone = createModuleSplit(BASE_MODULE_NAME.getName(), /* splitId= */
"", /* masterSplit= */
true, STANDALONE, /* languageTargeting= */
null);
ResourceTable standaloneResourceTable = new ResourceTableBuilder().addPackage("com.example.app").addStringResourceForMultipleLocales("title", ImmutableMap.of("ru-RU", "title ru-RU", "fr", "title fr")).build();
standalone = standalone.toBuilder().setResourceTable(standaloneResourceTable).build();
GeneratedApks generatedApks = GeneratedApks.fromModuleSplits(ImmutableList.of(standalone));
ModuleSplit processedStandalone = xmlInjectorProcess(generatedApks).stream().collect(onlyElement());
assertThat(processedStandalone.getAndroidManifest().getMetadataResourceId("com.android.vending.splits")).hasValue(0x7f020000);
assertThat(processedStandalone.getResourceTable().get()).containsResource("com.example.app:xml/splits0").withFileReference("res/xml/splits0.xml");
XmlNode expectedSplitsProtoXml = new SplitsProtoXmlBuilder().addLanguageMapping(BASE_MODULE_NAME, "ru", "").addLanguageMapping(BASE_MODULE_NAME, "fr", "").build();
assertThat(XmlNode.parseFrom(processedStandalone.getEntries().get(0).getContent().read())).ignoringRepeatedFieldOrder().isEqualTo(expectedSplitsProtoXml);
}
use of com.android.tools.build.bundletool.model.SplitsProtoXmlBuilder in project bundletool by google.
the class SplitsXmlInjectorTest method process_noLanguageTargeting.
@Test
public void process_noLanguageTargeting() throws Exception {
ResourceTable baseResourceTable = new ResourceTableBuilder().addPackage("com.example.app").addStringResourceForMultipleLocales("title", ImmutableMap.of("ru", "title ru-RU", "fr", "title fr", "es", "title es")).build();
ModuleSplit baseModule = createModuleSplit(BASE_MODULE_NAME.getName(), /* splitId= */
"", /* masterSplit= */
true, SPLIT, /* languageTargeting= */
null).toBuilder().setResourceTable(baseResourceTable).build();
ResourceTable featureResourceTable = new ResourceTableBuilder().addPackage("com.example.app.module").addStringResourceForMultipleLocales("module_str", ImmutableMap.of("ru", "module ru-RU")).build();
ModuleSplit featureModule = createModuleSplit("module", /* splitId= */
"module", /* masterSplit= */
true, SPLIT, /* languageTargeting= */
null).toBuilder().setResourceTable(featureResourceTable).build();
GeneratedApks generatedApks = GeneratedApks.fromModuleSplits(ImmutableList.of(baseModule, featureModule));
ModuleSplit processedBaseMasterSplit = xmlInjectorProcess(generatedApks).stream().filter(module -> module.isMasterSplit() && module.isBaseModuleSplit()).collect(onlyElement());
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").addLanguageMapping(BASE_MODULE_NAME, "ru", "").addLanguageMapping(BASE_MODULE_NAME, "fr", "").addLanguageMapping(BASE_MODULE_NAME, "es", "").build();
Optional<ModuleEntry> splitsXml = processedBaseMasterSplit.findEntry("res/xml/splits0.xml");
assertThat(splitsXml).isPresent();
assertThat(XmlNode.parseFrom(splitsXml.get().getContent().read(), ExtensionRegistry.getEmptyRegistry())).ignoringRepeatedFieldOrder().isEqualTo(expectedSplitsProtoXml);
}
use of com.android.tools.build.bundletool.model.SplitsProtoXmlBuilder in project bundletool by google.
the class SplitsXmlInjectorTest method process_systemSplits.
@Test
public void process_systemSplits() throws Exception {
ModuleSplit baseMasterSplit = createModuleSplit(BASE_MODULE_NAME.getName(), /* splitId= */
"", /* masterSplit= */
true, SYSTEM, languageTargeting("es"));
ImmutableList<ModuleSplit> otherSplits = ImmutableList.of(createModuleSplit(BASE_MODULE_NAME.getName(), /* splitId= */
"config.ru", /* masterSplit= */
false, SYSTEM, languageTargeting("ru")), createModuleSplit(BASE_MODULE_NAME.getName(), /* splitId= */
"config.fr", /* masterSplit= */
false, SYSTEM, languageTargeting("fr")), createModuleSplit("module", /* splitId= */
"module.config.ru", /* masterSplit= */
false, SYSTEM, 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").addLanguageMapping(BASE_MODULE_NAME, "es", "").build();
assertThat(XmlNode.parseFrom(processedBaseMasterSplit.getEntries().get(0).getContent().read())).ignoringRepeatedFieldOrder().isEqualTo(expectedSplitsProtoXml);
}
Aggregations