use of com.android.aapt.Resources.XmlNode in project bundletool by google.
the class LocaleConfigXmlInjector method processSplitApkVariant.
private static ImmutableList<ModuleSplit> processSplitApkVariant(ImmutableList<ModuleSplit> splits) {
// Only inject a locales_config.xml to the base module splits
boolean hasLanguageSplits = splits.stream().anyMatch(split -> split.isBaseModuleSplit() && split.getApkTargeting().hasLanguageTargeting());
XmlNode localesXmlContent = createLocalesXmlNode(splits);
ImmutableList.Builder<ModuleSplit> result = new ImmutableList.Builder<>();
for (ModuleSplit split : splits) {
// 6. The locales_config.xml doesn't exist in the resources(res/xml/).
if (split.isMasterSplit() && split.isBaseModuleSplit() && split.getResourceTable().isPresent() && hasLanguageSplits && !split.getAndroidManifest().hasLocaleConfig() && !split.findEntry(ZipPath.create(RESOURCE_PATH)).isPresent()) {
result.add(injectLocaleConfigXml(split, localesXmlContent));
} else {
result.add(split);
}
}
return result.build();
}
use of com.android.aapt.Resources.XmlNode in project bundletool by google.
the class ManifestEditorTest method complexManifest_featureSplit.
/**
* Tests the whole process of editing manifest to catch any unintended changes.
*/
@Test
public void complexManifest_featureSplit() throws Exception {
XmlNode.Builder xmlNodeBuilder = XmlNode.newBuilder();
TextFormat.merge(TestData.openReader("testdata/manifest/manifest1.textpb"), xmlNodeBuilder);
AndroidManifest androidManifest = AndroidManifest.create(xmlNodeBuilder.build());
XmlNode.Builder expectedXmlNodeBuilder = XmlNode.newBuilder();
TextFormat.merge(TestData.openReader("testdata/manifest/feature_split_manifest1.textpb"), expectedXmlNodeBuilder);
XmlNode generatedManifest = androidManifest.toEditor().setSplitIdForFeatureSplit("testModule").save().getManifestRoot().getProto();
assertThat(generatedManifest).isEqualTo(expectedXmlNodeBuilder.build());
}
use of com.android.aapt.Resources.XmlNode in project bundletool by google.
the class ManifestEditorTest method setFeatureSplit_isFeatureAttributePresent.
@Test
public void setFeatureSplit_isFeatureAttributePresent() throws Exception {
AndroidManifest androidManifest = AndroidManifest.create(xmlNode(xmlElement("manifest", xmlBooleanAttribute(ANDROID_NAMESPACE_URI, "isFeatureSplit", IS_FEATURE_SPLIT_RESOURCE_ID, false), xmlNode(xmlElement("application")))));
AndroidManifest editedManifest = androidManifest.toEditor().setSplitIdForFeatureSplit("feature1").save();
XmlNode manifestRoot = editedManifest.getManifestRoot().getProto();
assertThat(manifestRoot.hasElement()).isTrue();
XmlElement manifestElement = manifestRoot.getElement();
assertThat(manifestElement.getName()).isEqualTo("manifest");
assertThat(manifestElement.getChildList()).containsExactly(xmlNode(xmlElement("application")));
assertThat(manifestElement.getAttributeList()).containsExactly(xmlBooleanAttribute(ANDROID_NAMESPACE_URI, "isFeatureSplit", IS_FEATURE_SPLIT_RESOURCE_ID, true), xmlAttribute("split", "feature1"));
}
use of com.android.aapt.Resources.XmlNode in project bundletool by google.
the class ManifestEditorTest method addReceiver.
@Test
public void addReceiver() throws Exception {
Receiver receiver = Receiver.builder().setName("receiverName").build();
XmlNode receiverXmlNode = XmlNode.newBuilder().setElement(receiver.asXmlProtoElement().getProto()).build();
AndroidManifest androidManifest = AndroidManifest.create(androidManifest("com.test.app"));
AndroidManifest editedManifest = androidManifest.toEditor().addReceiver(receiver).save();
assertThat(getApplicationElement(editedManifest).getChildList()).containsExactly(receiverXmlNode);
}
use of com.android.aapt.Resources.XmlNode in project bundletool by google.
the class ManifestEditorTest method setMaxSdkVersion_nonExistingAttribute_created.
@Test
public void setMaxSdkVersion_nonExistingAttribute_created() throws Exception {
AndroidManifest androidManifest = AndroidManifest.create(xmlNode(xmlElement("manifest", xmlNode(xmlElement("uses-sdk")))));
AndroidManifest editedManifest = androidManifest.toEditor().setMaxSdkVersion(123).save();
XmlNode editedManifestRoot = editedManifest.getManifestRoot().getProto();
assertThat(editedManifestRoot.hasElement()).isTrue();
XmlElement manifestElement = editedManifestRoot.getElement();
assertThat(manifestElement.getName()).isEqualTo("manifest");
assertThat(manifestElement.getChildList()).containsExactly(xmlNode(xmlElement("uses-sdk", xmlDecimalIntegerAttribute(ANDROID_NAMESPACE_URI, "maxSdkVersion", MAX_SDK_VERSION_RESOURCE_ID, 123))));
}
Aggregations