Search in sources :

Example 16 with XmlProtoNode

use of com.android.tools.build.bundletool.model.utils.xmlproto.XmlProtoNode in project bundletool by google.

the class ManifestProtoUtils method androidManifestForAssetModule.

public static XmlNode androidManifestForAssetModule(String packageName, ManifestMutator... manifestMutators) {
    XmlNode manifestNode = xmlNode(xmlElement("manifest", ImmutableList.of(xmlNamespace("android", ANDROID_NAMESPACE_URI)), ImmutableList.of(xmlAttribute("package", packageName))));
    XmlProtoNodeBuilder xmlProtoNode = new XmlProtoNode(manifestNode).toBuilder();
    // Default mutators
    withTypeAttribute(MODULE_TYPE_ASSET_VALUE).accept(xmlProtoNode.getElement());
    withFusingAttribute(true).accept(xmlProtoNode.getElement());
    // Additional mutators and overrides of defaults.
    for (ManifestMutator manifestMutator : manifestMutators) {
        manifestMutator.accept(xmlProtoNode.getElement());
    }
    // Set a delivery mode if none was set.
    if (!AndroidManifest.create(xmlProtoNode.build().getProto()).isDeliveryTypeDeclared()) {
        withOnDemandDelivery().accept(xmlProtoNode.getElement());
    }
    return xmlProtoNode.build().getProto();
}
Also used : XmlProtoNodeBuilder(com.android.tools.build.bundletool.model.utils.xmlproto.XmlProtoNodeBuilder) XmlNode(com.android.aapt.Resources.XmlNode) XmlProtoNode(com.android.tools.build.bundletool.model.utils.xmlproto.XmlProtoNode)

Example 17 with XmlProtoNode

use of com.android.tools.build.bundletool.model.utils.xmlproto.XmlProtoNode in project bundletool by google.

the class ManifestProtoUtils method androidManifest.

/**
 * Creates an Android Manifest.
 *
 * <p>Without providing any {@code manifestMutator} creates a minimal valid manifest.
 */
public static XmlNode androidManifest(String packageName, ManifestMutator... manifestMutators) {
    XmlNode manifestNode = xmlNode(xmlElement("manifest", ImmutableList.of(xmlNamespace("android", ANDROID_NAMESPACE_URI)), ImmutableList.of(xmlAttribute("package", packageName), xmlDecimalIntegerAttribute(ANDROID_NAMESPACE_URI, "versionCode", 0x0101021b, 1))));
    XmlProtoNodeBuilder xmlProtoNode = new XmlProtoNode(manifestNode).toBuilder();
    withHasCode(false).accept(xmlProtoNode.getElement());
    for (ManifestMutator manifestMutator : manifestMutators) {
        manifestMutator.accept(xmlProtoNode.getElement());
    }
    return xmlProtoNode.build().getProto();
}
Also used : XmlProtoNodeBuilder(com.android.tools.build.bundletool.model.utils.xmlproto.XmlProtoNodeBuilder) XmlNode(com.android.aapt.Resources.XmlNode) XmlProtoNode(com.android.tools.build.bundletool.model.utils.xmlproto.XmlProtoNode)

Example 18 with XmlProtoNode

use of com.android.tools.build.bundletool.model.utils.xmlproto.XmlProtoNode in project bundletool by google.

the class BundleModuleBuilder method build.

public BundleModule build() {
    if (androidManifest != null) {
        XmlProtoNodeBuilder manifestBuilder = new XmlProtoNode(androidManifest).toBuilder();
        boolean hasCode = entries.build().stream().anyMatch(entry -> entry.getPath().toString().endsWith(".dex"));
        if (hasCode) {
            ManifestProtoUtils.clearHasCode().accept(manifestBuilder.getElement());
        }
        // Set the 'split' attribute if one is not already set.
        if (!moduleName.equals(BundleModuleName.BASE_MODULE_NAME) && !manifestBuilder.getElement().getAttribute("split").isPresent()) {
            ManifestProtoUtils.withSplitId(moduleName.getName()).accept(manifestBuilder.getElement());
        }
        addFile("manifest/AndroidManifest.xml", manifestBuilder.build().getProto().toByteArray());
    }
    return BundleModule.builder().setName(moduleName).addEntries(entries.build()).setBundleConfig(bundleConfig).build();
}
Also used : XmlProtoNodeBuilder(com.android.tools.build.bundletool.model.utils.xmlproto.XmlProtoNodeBuilder) XmlProtoNode(com.android.tools.build.bundletool.model.utils.xmlproto.XmlProtoNode)

Aggregations

XmlProtoNode (com.android.tools.build.bundletool.model.utils.xmlproto.XmlProtoNode)18 Test (org.junit.Test)12 Document (org.w3c.dom.Document)12 XmlNode (com.android.aapt.Resources.XmlNode)3 XmlProtoElement (com.android.tools.build.bundletool.model.utils.xmlproto.XmlProtoElement)3 XmlProtoNodeBuilder (com.android.tools.build.bundletool.model.utils.xmlproto.XmlProtoNodeBuilder)3 ZipPath (com.android.tools.build.bundletool.model.ZipPath)1 XmlProtoAttribute (com.android.tools.build.bundletool.model.utils.xmlproto.XmlProtoAttribute)1 XmlProtoNamespace (com.android.tools.build.bundletool.model.utils.xmlproto.XmlProtoNamespace)1 XPathResult (com.android.tools.build.bundletool.xml.XPathResolver.XPathResult)1 XmlNamespaceContext (com.android.tools.build.bundletool.xml.XmlNamespaceContext)1 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 UncheckedIOException (java.io.UncheckedIOException)1 XPath (javax.xml.xpath.XPath)1 XPathExpression (javax.xml.xpath.XPathExpression)1 XPathExpressionException (javax.xml.xpath.XPathExpressionException)1 Element (org.w3c.dom.Element)1