Search in sources :

Example 16 with XmlNode

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

the class BundleModuleMergerTest method testMultipleModulesWithInstallTime_throws_duplicateModuleEntriesWithDifferentContent.

@Test
public void testMultipleModulesWithInstallTime_throws_duplicateModuleEntriesWithDifferentContent() throws Exception {
    XmlNode installTimeModuleManifest = androidManifestForFeature("com.test.app.detail", withInstallTimeDelivery());
    createBasicZipBuilder(BUNDLE_CONFIG_1_0_0).addFileWithProtoContent(ZipPath.create("base/manifest/AndroidManifest.xml"), MANIFEST).addFileWithContent(ZipPath.create("base/dex/classes.dex"), DUMMY_CONTENT).addFileWithContent(ZipPath.create("base/assets/baseAssetfile.txt"), DUMMY_CONTENT).addFileWithProtoContent(ZipPath.create("detail1/manifest/AndroidManifest.xml"), installTimeModuleManifest).addFileWithContent(ZipPath.create("detail1/assets/detailsAssetfile.txt"), DUMMY_CONTENT).addFileWithProtoContent(ZipPath.create("detail2/manifest/AndroidManifest.xml"), installTimeModuleManifest).addFileWithContent(ZipPath.create("detail2/assets/baseAssetfile.txt"), DUMMY_CONTENT_2).writeTo(bundleFile);
    try (ZipFile appBundleZip = new ZipFile(bundleFile.toFile())) {
        InvalidBundleException exception = assertThrows(InvalidBundleException.class, () -> BundleModuleMerger.mergeNonRemovableInstallTimeModules(AppBundle.buildFromZip(appBundleZip), /* overrideBundleToolVersion = */
        false));
        assertThat(exception).hasMessageThat().contains("Existing module entry 'assets/baseAssetfile.txt' with different contents.");
    }
}
Also used : XmlNode(com.android.aapt.Resources.XmlNode) ZipFile(java.util.zip.ZipFile) InvalidBundleException(com.android.tools.build.bundletool.model.exceptions.InvalidBundleException) Test(org.junit.Test)

Example 17 with XmlNode

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

the class BundleModuleMergerTest method testMultipleModulesWithInstallTime_noMergingIfBuiltWithOlderBundleTool.

@Test
public void testMultipleModulesWithInstallTime_noMergingIfBuiltWithOlderBundleTool() throws Exception {
    XmlNode installTimeModuleManifest = androidManifestForFeature("com.test.app.detail", withInstallTimeDelivery());
    createBasicZipBuilder(BUNDLE_CONFIG_0_14_0).addFileWithProtoContent(ZipPath.create("base/manifest/AndroidManifest.xml"), MANIFEST).addFileWithContent(ZipPath.create("base/dex/classes.dex"), DUMMY_CONTENT).addFileWithContent(ZipPath.create("base/assets/baseAssetfile.txt"), DUMMY_CONTENT).addFileWithProtoContent(ZipPath.create("detail/manifest/AndroidManifest.xml"), installTimeModuleManifest).addFileWithContent(ZipPath.create("detail/assets/detailsAssetfile.txt"), DUMMY_CONTENT).writeTo(bundleFile);
    try (ZipFile appBundleZip = new ZipFile(bundleFile.toFile())) {
        AppBundle appBundle = BundleModuleMerger.mergeNonRemovableInstallTimeModules(AppBundle.buildFromZip(appBundleZip), /* overrideBundleToolVersion = */
        false);
        assertThat(appBundle.getFeatureModules().keySet()).comparingElementsUsing(equalsBundleModuleName()).containsExactly("base", "detail");
    }
}
Also used : XmlNode(com.android.aapt.Resources.XmlNode) AppBundle(com.android.tools.build.bundletool.model.AppBundle) ZipFile(java.util.zip.ZipFile) Test(org.junit.Test)

Example 18 with XmlNode

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

the class BundleModuleMergerTest method testMultipleModulesWithInstallTime_bundleToolVersionOverrideIgnored.

// Override ignored for bundles built by bundletool version >= 1.0.0. Allows developers to
// selectively merge modules.
@Test
public void testMultipleModulesWithInstallTime_bundleToolVersionOverrideIgnored() throws Exception {
    XmlNode installTimeModuleManifest = androidManifestForFeature("com.test.app.detail", withInstallTimeDelivery());
    XmlNode installTimeNonRemovableModuleManifest = androidManifestForFeature("com.test.app.detail", withInstallTimeRemovableElement(false));
    XmlNode installTimeRemovableModuleManifest = androidManifestForFeature("com.test.app.detail", withInstallTimeRemovableElement(true));
    createBasicZipBuilder(BUNDLE_CONFIG_1_0_0).addFileWithProtoContent(ZipPath.create("base/manifest/AndroidManifest.xml"), MANIFEST).addFileWithContent(ZipPath.create("base/dex/classes.dex"), DUMMY_CONTENT).addFileWithContent(ZipPath.create("base/assets/baseAssetfile.txt"), DUMMY_CONTENT).addFileWithProtoContent(ZipPath.create("detail/manifest/AndroidManifest.xml"), installTimeModuleManifest).addFileWithContent(ZipPath.create("detail/assets/detailsAssetfile.txt"), DUMMY_CONTENT).addFileWithProtoContent(ZipPath.create("detail2/manifest/AndroidManifest.xml"), installTimeNonRemovableModuleManifest).addFileWithContent(ZipPath.create("detail2/assets/detailsAssetfile.txt"), DUMMY_CONTENT).addFileWithProtoContent(ZipPath.create("detail3/manifest/AndroidManifest.xml"), installTimeRemovableModuleManifest).addFileWithContent(ZipPath.create("detail3/assets/detailsAssetfile.txt"), DUMMY_CONTENT).writeTo(bundleFile);
    try (ZipFile appBundleZip = new ZipFile(bundleFile.toFile())) {
        AppBundle appBundle = BundleModuleMerger.mergeNonRemovableInstallTimeModules(AppBundle.buildFromZip(appBundleZip), /* overrideBundleToolVersion = */
        true);
        assertThat(appBundle.getFeatureModules().keySet()).comparingElementsUsing(equalsBundleModuleName()).containsExactly("base", "detail3");
    }
}
Also used : XmlNode(com.android.aapt.Resources.XmlNode) AppBundle(com.android.tools.build.bundletool.model.AppBundle) ZipFile(java.util.zip.ZipFile) Test(org.junit.Test)

Example 19 with XmlNode

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

the class BundleModuleMergerTest method testDoNotMergeIfConditionalModule.

@Test
public void testDoNotMergeIfConditionalModule() throws Exception {
    XmlNode conditionalModuleManifest = androidManifest("com.test.app.detail", withMinSdkVersion(24), withFeatureCondition("android.feature"));
    createBasicZipBuilder(BUNDLE_CONFIG_1_0_0).addFileWithProtoContent(ZipPath.create("base/manifest/AndroidManifest.xml"), MANIFEST).addFileWithContent(ZipPath.create("base/dex/classes.dex"), DUMMY_CONTENT).addFileWithContent(ZipPath.create("base/assets/baseAssetfile.txt"), DUMMY_CONTENT).addFileWithProtoContent(ZipPath.create("detail/manifest/AndroidManifest.xml"), conditionalModuleManifest).addFileWithContent(ZipPath.create("detail/assets/detailsAssetfile.txt"), DUMMY_CONTENT).writeTo(bundleFile);
    try (ZipFile appBundleZip = new ZipFile(bundleFile.toFile())) {
        AppBundle appBundle = BundleModuleMerger.mergeNonRemovableInstallTimeModules(AppBundle.buildFromZip(appBundleZip), /* overrideBundleToolVersion = */
        false);
        assertThat(appBundle.getFeatureModules().keySet()).comparingElementsUsing(equalsBundleModuleName()).containsExactly("base", "detail");
    }
}
Also used : XmlNode(com.android.aapt.Resources.XmlNode) AppBundle(com.android.tools.build.bundletool.model.AppBundle) ZipFile(java.util.zip.ZipFile) Test(org.junit.Test)

Example 20 with XmlNode

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

the class ManifestDeliveryElementTest method deliveryElement_typoInChildElement_throws_fastFollowEnabled.

@Test
public void deliveryElement_typoInChildElement_throws_fastFollowEnabled() {
    XmlNode nodeWithTypo = createAndroidManifestWithDeliveryElement(XmlProtoElementBuilder.create(DISTRIBUTION_NAMESPACE_URI, "delivery").addChildElement(XmlProtoElementBuilder.create(DISTRIBUTION_NAMESPACE_URI, "instal-time")));
    InvalidBundleException exception = assertThrows(InvalidBundleException.class, () -> ManifestDeliveryElement.fromManifestRootNode(nodeWithTypo, /* isFastFollowAllowed= */
    true));
    assertThat(exception).hasMessageThat().contains("Expected <dist:delivery> element to contain only <dist:install-time>, " + "<dist:on-demand>, <dist:fast-follow> elements but found: 'instal-time' " + "with namespace URI: 'http://schemas.android.com/apk/distribution'");
}
Also used : XmlNode(com.android.aapt.Resources.XmlNode) InvalidBundleException(com.android.tools.build.bundletool.model.exceptions.InvalidBundleException) 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