Search in sources :

Example 71 with AppBundle

use of com.android.tools.build.bundletool.model.AppBundle in project bundletool by google.

the class BundleModuleMergerTest method testMultipleModulesWithInstallTime_implicitMergingDexRenaming.

@Test
public void testMultipleModulesWithInstallTime_implicitMergingDexRenaming() 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("detail/manifest/AndroidManifest.xml"), installTimeModuleManifest).addFileWithContent(ZipPath.create("detail/assets/detailsAssetfile.txt"), DUMMY_CONTENT).addFileWithContent(ZipPath.create("detail/dex/classes.dex"), DUMMY_CONTENT).writeTo(bundleFile);
    try (ZipFile appBundleZip = new ZipFile(bundleFile.toFile())) {
        AppBundle appBundlePreMerge = AppBundle.buildFromZip(appBundleZip);
        AppBundle appBundlePostMerge = BundleModuleMerger.mergeNonRemovableInstallTimeModules(appBundlePreMerge, /* overrideBundleToolVersion = */
        false);
        assertThat(appBundlePostMerge.getModules().keySet().stream().map(BundleModuleName::getName)).containsExactly("base");
        assertThat(appBundlePreMerge.getModules().values().stream().mapToLong(module -> module.getEntries().size()).sum()).isEqualTo(appBundlePostMerge.getModules().values().stream().mapToLong(module -> module.getEntries().size()).sum());
        assertThat(appBundlePostMerge.getBaseModule().getEntry(ZipPath.create("dex/classes.dex"))).isPresent();
        assertThat(appBundlePostMerge.getBaseModule().getEntry(ZipPath.create("dex/classes2.dex"))).isPresent();
    }
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) ManifestProtoUtils.withFeatureCondition(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withFeatureCondition) ManifestProtoUtils.withMetadataValue(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withMetadataValue) ManifestProtoUtils.withSplitNameActivity(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withSplitNameActivity) BundleModuleName(com.android.tools.build.bundletool.model.BundleModuleName) ZipPath(com.android.tools.build.bundletool.model.ZipPath) ManifestProtoUtils.androidManifest(com.android.tools.build.bundletool.testing.ManifestProtoUtils.androidManifest) BundleConfigBuilder(com.android.tools.build.bundletool.testing.BundleConfigBuilder) RunWith(org.junit.runner.RunWith) ZipBuilder(com.android.tools.build.bundletool.io.ZipBuilder) ManifestProtoUtils.androidManifestForAssetModule(com.android.tools.build.bundletool.testing.ManifestProtoUtils.androidManifestForAssetModule) ProtoTruth.assertThat(com.google.common.truth.extensions.proto.ProtoTruth.assertThat) ManifestProtoUtils.withOnDemandDelivery(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withOnDemandDelivery) ZipFile(java.util.zip.ZipFile) ManifestProtoUtils.androidManifestForMlModule(com.android.tools.build.bundletool.testing.ManifestProtoUtils.androidManifestForMlModule) ManifestProtoUtils.withSplitNameService(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withSplitNameService) Truth8.assertThat(com.google.common.truth.Truth8.assertThat) Path(java.nio.file.Path) Before(org.junit.Before) InvalidBundleException(com.android.tools.build.bundletool.model.exceptions.InvalidBundleException) TestData(com.android.tools.build.bundletool.TestData) FileOutputStream(java.io.FileOutputStream) Test(org.junit.Test) JUnit4(org.junit.runners.JUnit4) Truth.assertThat(com.google.common.truth.Truth.assertThat) Collectors(java.util.stream.Collectors) ManifestProtoUtils.withInstallTimeRemovableElement(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withInstallTimeRemovableElement) File(java.io.File) Correspondence(com.google.common.truth.Correspondence) ManifestProtoUtils.withMinSdkVersion(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withMinSdkVersion) Stream(java.util.stream.Stream) Rule(org.junit.Rule) XmlNode(com.android.aapt.Resources.XmlNode) BundleConfig(com.android.bundle.Config.BundleConfig) ManifestProtoUtils.withInstallTimeDelivery(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withInstallTimeDelivery) ManifestProtoUtils.androidManifestForFeature(com.android.tools.build.bundletool.testing.ManifestProtoUtils.androidManifestForFeature) AppBundle(com.android.tools.build.bundletool.model.AppBundle) TemporaryFolder(org.junit.rules.TemporaryFolder) XmlNode(com.android.aapt.Resources.XmlNode) AppBundle(com.android.tools.build.bundletool.model.AppBundle) BundleModuleName(com.android.tools.build.bundletool.model.BundleModuleName) ZipFile(java.util.zip.ZipFile) Test(org.junit.Test)

Example 72 with AppBundle

use of com.android.tools.build.bundletool.model.AppBundle in project bundletool by google.

the class BundleModuleMergerTest method fuseOnlyActivitiesInManifest_1_0_0.

@Test
public void fuseOnlyActivitiesInManifest_1_0_0() throws Exception {
    XmlNode installTimeModuleManifest = androidManifestForFeature("com.test.app.detail", withInstallTimeDelivery(), withSplitNameActivity("activity1", "detail"), withSplitNameService("service", "detail"));
    createBasicZipBuilder(BUNDLE_CONFIG_1_0_0).addFileWithProtoContent(ZipPath.create("base/manifest/AndroidManifest.xml"), MANIFEST).addFileWithProtoContent(ZipPath.create("detail/manifest/AndroidManifest.xml"), installTimeModuleManifest).writeTo(bundleFile);
    try (ZipFile appBundleZip = new ZipFile(bundleFile.toFile())) {
        AppBundle appBundle = BundleModuleMerger.mergeNonRemovableInstallTimeModules(AppBundle.buildFromZip(appBundleZip), /* overrideBundleToolVersion = */
        false);
        XmlNode fusedManifest = androidManifest("com.test.app.detail", withSplitNameActivity("activity1", "detail"), withMetadataValue("com.android.dynamic.apk.fused.modules", "base,detail"));
        assertThat(appBundle.getBaseModule().getAndroidManifest().getManifestRoot().getProto()).isEqualTo(fusedManifest);
    }
}
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 73 with AppBundle

use of com.android.tools.build.bundletool.model.AppBundle 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 74 with AppBundle

use of com.android.tools.build.bundletool.model.AppBundle 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 75 with AppBundle

use of com.android.tools.build.bundletool.model.AppBundle 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)

Aggregations

AppBundle (com.android.tools.build.bundletool.model.AppBundle)205 Test (org.junit.Test)193 AppBundleBuilder (com.android.tools.build.bundletool.testing.AppBundleBuilder)137 ZipFile (java.util.zip.ZipFile)136 ManifestProtoUtils.androidManifest (com.android.tools.build.bundletool.testing.ManifestProtoUtils.androidManifest)112 Truth.assertThat (com.google.common.truth.Truth.assertThat)112 Path (java.nio.file.Path)112 RunWith (org.junit.runner.RunWith)112 BuildApksResult (com.android.bundle.Commands.BuildApksResult)106 AppBundleSerializer (com.android.tools.build.bundletool.io.AppBundleSerializer)104 ImmutableList (com.google.common.collect.ImmutableList)102 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)101 InvalidBundleException (com.android.tools.build.bundletool.model.exceptions.InvalidBundleException)100 Before (org.junit.Before)100 Rule (org.junit.Rule)100 TemporaryFolder (org.junit.rules.TemporaryFolder)100 Variant (com.android.bundle.Commands.Variant)98 IOException (java.io.IOException)94 ApkDescription (com.android.bundle.Commands.ApkDescription)90 ApkSetUtils.extractTocFromApkSetFile (com.android.tools.build.bundletool.testing.ApkSetUtils.extractTocFromApkSetFile)87