Search in sources :

Example 51 with XmlNode

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();
}
Also used : XmlNode(com.android.aapt.Resources.XmlNode) ImmutableList(com.google.common.collect.ImmutableList) XmlProtoElementBuilder(com.android.tools.build.bundletool.model.utils.xmlproto.XmlProtoElementBuilder) XmlProtoAttributeBuilder(com.android.tools.build.bundletool.model.utils.xmlproto.XmlProtoAttributeBuilder) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit)

Example 52 with XmlNode

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());
}
Also used : XmlNode(com.android.aapt.Resources.XmlNode) Test(org.junit.Test)

Example 53 with XmlNode

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"));
}
Also used : XmlNode(com.android.aapt.Resources.XmlNode) XmlElement(com.android.aapt.Resources.XmlElement) Test(org.junit.Test)

Example 54 with XmlNode

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);
}
Also used : XmlNode(com.android.aapt.Resources.XmlNode) Receiver(com.android.tools.build.bundletool.model.manifestelements.Receiver) Test(org.junit.Test)

Example 55 with XmlNode

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))));
}
Also used : XmlNode(com.android.aapt.Resources.XmlNode) XmlElement(com.android.aapt.Resources.XmlElement) Test(org.junit.Test)

Aggregations

XmlNode (com.android.aapt.Resources.XmlNode)99 Test (org.junit.Test)91 XmlElement (com.android.aapt.Resources.XmlElement)28 AppBundle (com.android.tools.build.bundletool.model.AppBundle)27 ManifestProtoUtils.androidManifest (com.android.tools.build.bundletool.testing.ManifestProtoUtils.androidManifest)23 Truth.assertThat (com.google.common.truth.Truth.assertThat)23 RunWith (org.junit.runner.RunWith)23 ResourceTable (com.android.aapt.Resources.ResourceTable)21 ImmutableList (com.google.common.collect.ImmutableList)21 AndroidManifest (com.android.tools.build.bundletool.model.AndroidManifest)16 Nullable (javax.annotation.Nullable)16 Theories (org.junit.experimental.theories.Theories)16 ZipFile (java.util.zip.ZipFile)12 FileReference (com.android.aapt.Resources.FileReference)10 AppBundleBuilder (com.android.tools.build.bundletool.testing.AppBundleBuilder)10 Configuration (com.android.aapt.ConfigurationOuterClass.Configuration)9 Attribute (com.android.aapt.Resources.Attribute)9 Symbol (com.android.aapt.Resources.Attribute.Symbol)9 CompoundValue (com.android.aapt.Resources.CompoundValue)9 ConfigValue (com.android.aapt.Resources.ConfigValue)9