use of com.android.aapt.Resources.XmlNode 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.aapt.Resources.XmlNode in project bundletool by google.
the class XmlProtoElementTest method getChildrenText_noTextChildren.
@Test
public void getChildrenText_noTextChildren() {
XmlNode childElement = XmlNode.newBuilder().setElement(XmlElement.newBuilder().setName("element")).build();
XmlProtoElement element = new XmlProtoElement(XmlElement.newBuilder().setName("hello").addChild(childElement).build());
assertThat(element.getChildrenText()).isEmpty();
}
use of com.android.aapt.Resources.XmlNode in project bundletool by google.
the class XmlProtoElementTest method getChildText.
@Test
public void getChildText() {
XmlNode child = XmlNode.newBuilder().setText("child").build();
XmlProtoElement element = new XmlProtoElement(XmlElement.newBuilder().setName("hello").addChild(child).build());
assertThat(element.getChildText()).hasValue(new XmlProtoNode(child));
}
use of com.android.aapt.Resources.XmlNode in project bundletool by google.
the class SplitsXmlInjector method processSplitApkVariant.
private static ImmutableList<ModuleSplit> processSplitApkVariant(Collection<ModuleSplit> splits) {
boolean hasLanguageSplits = splits.stream().anyMatch(split -> split.getApkTargeting().hasLanguageTargeting());
// If language splits are available we gather language mappings from these splits otherwise this
// means that language splits are not generated and we need to gather all languages from
// resource table of master splits.
// We need to check splits targeting and can not rely on disabled language dimension because in
// case of system variant it is possible to generate splits that don't have language targeting
// for bundles with enabled language dimension.
XmlNode splitsXmlContent = hasLanguageSplits ? getSplitsXmlContentFromLanguageTargeting(splits) : getSplitsXmlContentFromResourceTables(splits);
ImmutableList.Builder<ModuleSplit> result = new ImmutableList.Builder<>();
for (ModuleSplit split : splits) {
if (split.isMasterSplit() && split.isBaseModuleSplit()) {
result.add(injectSplitsXml(split, splitsXmlContent));
} else {
result.add(split);
}
}
return result.build();
}
use of com.android.aapt.Resources.XmlNode in project bundletool by google.
the class LocaleConfigXmlInjector method createLocalesXmlNode.
public static XmlNode createLocalesXmlNode(ImmutableList<ModuleSplit> splits) {
// Get all locales from the base module splits
ImmutableSet<String> allLocales = getLocalesFromBaseModuleSplits(splits);
XmlProtoElementBuilder localesConfigXml = XmlProtoElementBuilder.create(LOCALE_CONFIG_ELEMENT);
allLocales.stream().filter(locale -> !locale.isEmpty()).forEach(locale -> localesConfigXml.addChildElement(createAttributes(locale)));
return XmlProtoNode.createElementNode(localesConfigXml.build()).getProto();
}
Aggregations