Search in sources :

Example 26 with XmlNode

use of com.android.aapt.Resources.XmlNode in project bundletool by google.

the class ManifestEditorTest method setVersionCode.

@Test
public void setVersionCode() {
    AndroidManifest androidManifest = createManifestWithApplicationElement();
    AndroidManifest editedManifest = androidManifest.toEditor().setVersionCode(123).save();
    XmlNode manifestRoot = editedManifest.getManifestRoot().getProto();
    assertThat(manifestRoot.hasElement()).isTrue();
    XmlElement manifestElement = manifestRoot.getElement();
    assertThat(manifestElement.getName()).isEqualTo("manifest");
    assertThat(manifestElement.getAttributeList()).containsExactly(xmlDecimalIntegerAttribute(ANDROID_NAMESPACE_URI, "versionCode", VERSION_CODE_RESOURCE_ID, 123));
}
Also used : XmlNode(com.android.aapt.Resources.XmlNode) XmlElement(com.android.aapt.Resources.XmlElement) Test(org.junit.Test)

Example 27 with XmlNode

use of com.android.aapt.Resources.XmlNode in project bundletool by google.

the class ManifestEditorTest method setSharedUserId.

@Test
public void setSharedUserId() {
    AndroidManifest androidManifest = createManifestWithApplicationElement();
    AndroidManifest editedManifest = androidManifest.toEditor().setSharedUserId("shared_user_id").save();
    XmlNode manifestRoot = editedManifest.getManifestRoot().getProto();
    assertThat(manifestRoot.getElement().getAttributeList()).containsExactly(xmlAttribute(ANDROID_NAMESPACE_URI, SHARED_USER_ID_ATTRIBUTE_NAME, SHARED_USER_ID_RESOURCE_ID, "shared_user_id"));
}
Also used : XmlNode(com.android.aapt.Resources.XmlNode) Test(org.junit.Test)

Example 28 with XmlNode

use of com.android.aapt.Resources.XmlNode in project bundletool by google.

the class ManifestEditorTest method addActivity.

@Test
public void addActivity() throws Exception {
    Activity activity = Activity.builder().setName("activityName").build();
    XmlNode activityXmlNode = XmlNode.newBuilder().setElement(activity.asXmlProtoElement().getProto()).build();
    AndroidManifest androidManifest = AndroidManifest.create(androidManifest("com.test.app"));
    AndroidManifest editedManifest = androidManifest.toEditor().addActivity(activity).save();
    assertThat(getApplicationElement(editedManifest).getChildList()).containsExactly(activityXmlNode);
}
Also used : XmlNode(com.android.aapt.Resources.XmlNode) ManifestProtoUtils.withSplitNameActivity(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withSplitNameActivity) Activity(com.android.tools.build.bundletool.model.manifestelements.Activity) ManifestProtoUtils.withMainActivity(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withMainActivity) Test(org.junit.Test)

Example 29 with XmlNode

use of com.android.aapt.Resources.XmlNode in project bundletool by google.

the class ManifestEditorTest method assertOnlyMetadataElement.

private static void assertOnlyMetadataElement(AndroidManifest manifest, String name, XmlAttribute valueAttr) {
    XmlElement applicationElement = getApplicationElement(manifest);
    assertThat(applicationElement.getChildCount()).isEqualTo(1);
    XmlNode metadataNode = applicationElement.getChild(0);
    XmlElement metadataElement = metadataNode.getElement();
    assertThat(metadataElement.getName()).isEqualTo("meta-data");
    assertThat(metadataElement.getAttributeList()).containsExactly(xmlAttribute(ANDROID_NAMESPACE_URI, "name", NAME_RESOURCE_ID, name), valueAttr);
}
Also used : XmlNode(com.android.aapt.Resources.XmlNode) XmlElement(com.android.aapt.Resources.XmlElement)

Example 30 with XmlNode

use of com.android.aapt.Resources.XmlNode in project bundletool by google.

the class BundleModuleTest method correctProtoManifestFile_parsedAndReturned.

@Test
public void correctProtoManifestFile_parsedAndReturned() throws Exception {
    XmlNode manifestXml = androidManifest("com.test.app");
    BundleModule bundleModule = BundleModule.builder().setName(BundleModuleName.create("testModule")).setBundleConfig(DEFAULT_BUNDLE_CONFIG).addEntry(createModuleEntryForFile("manifest/AndroidManifest.xml", manifestXml.toByteArray())).build();
    assertThat(bundleModule.getAndroidManifest().getManifestRoot().getProto()).isEqualTo(manifestXml);
}
Also used : XmlNode(com.android.aapt.Resources.XmlNode) 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