Search in sources :

Example 6 with ConfigurationSizes

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

the class VariantTotalSizeAggregatorTest method splitVariant_multipleModules_selectModules.

@Test
public void splitVariant_multipleModules_selectModules() {
    Variant lVariant = createVariant(lPlusVariantTargeting(), createSplitApkSet(/* moduleName= */
    "base", createMasterApkDescription(ApkTargeting.getDefaultInstance(), ZipPath.create("base-master.apk"))), createSplitApkSet(/* moduleName= */
    "feature", DeliveryType.ON_DEMAND, /* moduleDependencies= */
    ImmutableList.of(), createMasterApkDescription(ApkTargeting.getDefaultInstance(), ZipPath.create("feature-master.apk"))), createSplitApkSet(/* moduleName= */
    "feature1", DeliveryType.ON_DEMAND, /* moduleDependencies= */
    ImmutableList.of(), createMasterApkDescription(ApkTargeting.getDefaultInstance(), ZipPath.create("feature1-master.apk"))), createSplitApkSet(/* moduleName= */
    "feature2", createMasterApkDescription(ApkTargeting.getDefaultInstance(), ZipPath.create("feature2-master.apk"))));
    ConfigurationSizes configurationSizes = new VariantTotalSizeAggregator(ImmutableMap.<String, Long>builder().put("base-master.apk", 10L).put("feature-master.apk", 15L).put("feature1-master.apk", 6L).put("feature2-master.apk", 4L).build(), BundleToolVersion.getCurrentVersion(), lVariant, getSizeCommand.setModules(ImmutableSet.of("base", "feature1")).build()).getSize();
    // base, feature1, feature2 (install-time) modules are selected.
    assertThat(configurationSizes.getMaxSizeConfigurationMap()).containsExactly(SizeConfiguration.getDefaultInstance(), 20L);
    assertThat(configurationSizes.getMinSizeConfigurationMap()).containsExactly(SizeConfiguration.getDefaultInstance(), 20L);
}
Also used : Variant(com.android.bundle.Commands.Variant) ApksArchiveHelpers.standaloneVariant(com.android.tools.build.bundletool.testing.ApksArchiveHelpers.standaloneVariant) ApksArchiveHelpers.createVariant(com.android.tools.build.bundletool.testing.ApksArchiveHelpers.createVariant) ConfigurationSizes(com.android.tools.build.bundletool.model.ConfigurationSizes) Test(org.junit.Test)

Example 7 with ConfigurationSizes

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

the class GetSizeCommandTest method getSizeTotalInternal_multipleDimensions.

@Test
public void getSizeTotalInternal_multipleDimensions() throws Exception {
    Variant lVariant = createVariant(lPlusVariantTargeting(), createSplitApkSet(/* moduleName= */
    "base", createMasterApkDescription(ApkTargeting.getDefaultInstance(), ZipPath.create("base-master.apk")), createApkDescription(apkDensityTargeting(LDPI, ImmutableSet.of(MDPI)), ZipPath.create("base-ldpi.apk"), /* isMasterSplit= */
    false), createApkDescription(apkDensityTargeting(MDPI, ImmutableSet.of(LDPI)), ZipPath.create("base-mdpi.apk"), /* isMasterSplit= */
    false)));
    Variant preLVariant = standaloneVariant(mergeVariantTargeting(variantSdkTargeting(sdkVersionFrom(15), ImmutableSet.of(sdkVersionFrom(21))), variantAbiTargeting(ARMEABI, ImmutableSet.of(X86))), ApkTargeting.getDefaultInstance(), ZipPath.create("preL.apk"));
    BuildApksResult tableOfContentsProto = BuildApksResult.newBuilder().setBundletool(Bundletool.newBuilder().setVersion(BundleToolVersion.getCurrentVersion().toString())).addVariant(lVariant).addVariant(preLVariant).build();
    Path apksArchiveFile = createApksArchiveFile(tableOfContentsProto, tmpDir.resolve("bundle.apks"));
    ConfigurationSizes configurationSizes = GetSizeCommand.builder().setGetSizeSubCommand(GetSizeSubcommand.TOTAL).setApksArchivePath(apksArchiveFile).setDimensions(ImmutableSet.of(Dimension.SDK, Dimension.ABI, Dimension.LANGUAGE, Dimension.SCREEN_DENSITY)).build().getSizeTotalInternal();
    assertThat(configurationSizes.getMinSizeConfigurationMap()).containsExactly(SizeConfiguration.builder().setSdkVersion("21-").setScreenDensity("LDPI").build(), 2 * compressedApkSize, SizeConfiguration.builder().setSdkVersion("21-").setScreenDensity("MDPI").build(), 2 * compressedApkSize, SizeConfiguration.builder().setSdkVersion("15-20").setAbi("armeabi").build(), compressedApkSize);
    assertThat(configurationSizes.getMaxSizeConfigurationMap()).containsExactly(SizeConfiguration.builder().setSdkVersion("21-").setScreenDensity("LDPI").build(), 2 * compressedApkSize, SizeConfiguration.builder().setSdkVersion("21-").setScreenDensity("MDPI").build(), 2 * compressedApkSize, SizeConfiguration.builder().setSdkVersion("15-20").setAbi("armeabi").build(), compressedApkSize);
}
Also used : Variant(com.android.bundle.Commands.Variant) ApksArchiveHelpers.standaloneVariant(com.android.tools.build.bundletool.testing.ApksArchiveHelpers.standaloneVariant) ApksArchiveHelpers.createVariant(com.android.tools.build.bundletool.testing.ApksArchiveHelpers.createVariant) Path(java.nio.file.Path) ZipPath(com.android.tools.build.bundletool.model.ZipPath) BuildApksResult(com.android.bundle.Commands.BuildApksResult) ConfigurationSizes(com.android.tools.build.bundletool.model.ConfigurationSizes) Test(org.junit.Test)

Example 8 with ConfigurationSizes

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

the class GetSizeCommandTest method getSizeTotalInternal_singleSplitVariant.

@Test
public void getSizeTotalInternal_singleSplitVariant() throws Exception {
    Variant lVariant = createVariant(lPlusVariantTargeting(), createSplitApkSet(/* moduleName= */
    "base", createMasterApkDescription(ApkTargeting.getDefaultInstance(), ZipPath.create("base-master.apk")), createApkDescription(apkAbiTargeting(X86, ImmutableSet.of(X86_64)), ZipPath.create("base-x86.apk"), /* isMasterSplit= */
    false), createApkDescription(apkAbiTargeting(X86_64, ImmutableSet.of(X86)), ZipPath.create("base-x86_64.apk"), /* isMasterSplit= */
    false)));
    ZipBuilder archiveBuilder = new ZipBuilder();
    archiveBuilder.addFileWithContent(ZipPath.create("base-master.apk"), DUMMY_BYTES);
    archiveBuilder.addFileWithContent(ZipPath.create("base-x86.apk"), DUMMY_BYTES, // APK stored uncompressed in the APKs zip.
    EntryOption.UNCOMPRESSED);
    archiveBuilder.addFileWithContent(ZipPath.create("base-x86_64.apk"), new byte[10000]);
    archiveBuilder.addFileWithProtoContent(ZipPath.create("toc.pb"), BuildApksResult.newBuilder().setBundletool(Bundletool.newBuilder().setVersion(BundleToolVersion.getCurrentVersion().toString())).addVariant(lVariant).build());
    Path apksArchiveFile = archiveBuilder.writeTo(tmpDir.resolve("bundle.apks"));
    ConfigurationSizes configurationSizes = GetSizeCommand.builder().setGetSizeSubCommand(GetSizeSubcommand.TOTAL).setApksArchivePath(apksArchiveFile).build().getSizeTotalInternal();
    assertThat(configurationSizes.getMinSizeConfigurationMap().keySet()).containsExactly(SizeConfiguration.getDefaultInstance());
    assertThat(configurationSizes.getMinSizeConfigurationMap().get(SizeConfiguration.getDefaultInstance())).isEqualTo(// base+x86
    2 * compressedApkSize);
    assertThat(configurationSizes.getMaxSizeConfigurationMap().keySet()).containsExactly(SizeConfiguration.getDefaultInstance());
    assertThat(configurationSizes.getMaxSizeConfigurationMap().get(SizeConfiguration.getDefaultInstance())).isGreaterThan(// base+x86_64
    2 * compressedApkSize);
}
Also used : Variant(com.android.bundle.Commands.Variant) ApksArchiveHelpers.standaloneVariant(com.android.tools.build.bundletool.testing.ApksArchiveHelpers.standaloneVariant) ApksArchiveHelpers.createVariant(com.android.tools.build.bundletool.testing.ApksArchiveHelpers.createVariant) Path(java.nio.file.Path) ZipPath(com.android.tools.build.bundletool.model.ZipPath) ConfigurationSizes(com.android.tools.build.bundletool.model.ConfigurationSizes) ZipBuilder(com.android.tools.build.bundletool.io.ZipBuilder) Test(org.junit.Test)

Example 9 with ConfigurationSizes

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

the class GetSizeCommandTest method getSizeTotalInternal_withNoDimensionsAndDeviceSpec.

@Test
public void getSizeTotalInternal_withNoDimensionsAndDeviceSpec() throws Exception {
    Variant lVariant = createVariant(lPlusVariantTargeting(), createSplitApkSet(/* moduleName= */
    "base", createMasterApkDescription(ApkTargeting.getDefaultInstance(), ZipPath.create("base-master.apk"))));
    Variant preLVariant = standaloneVariant(mergeVariantTargeting(variantSdkTargeting(sdkVersionFrom(1), ImmutableSet.of(sdkVersionFrom(21))), variantAbiTargeting(X86, ImmutableSet.of(ARMEABI_V7A, ARM64_V8A))), ApkTargeting.getDefaultInstance(), ZipPath.create("preL.apk"));
    ZipBuilder archiveBuilder = new ZipBuilder();
    archiveBuilder.addFileWithContent(ZipPath.create("base-master.apk"), DUMMY_BYTES);
    archiveBuilder.addFileWithContent(ZipPath.create("preL.apk"), new byte[10000]);
    archiveBuilder.addFileWithProtoContent(ZipPath.create("toc.pb"), BuildApksResult.newBuilder().setBundletool(Bundletool.newBuilder().setVersion(BundleToolVersion.getCurrentVersion().toString())).addVariant(lVariant).addVariant(preLVariant).build());
    Path apksArchiveFile = archiveBuilder.writeTo(tmpDir.resolve("bundle.apks"));
    ConfigurationSizes configurationSizes = GetSizeCommand.builder().setGetSizeSubCommand(GetSizeSubcommand.TOTAL).setApksArchivePath(apksArchiveFile).setDeviceSpec(DeviceSpec.newBuilder().setSdkVersion(21).build()).build().getSizeTotalInternal();
    assertThat(configurationSizes.getMinSizeConfigurationMap()).containsExactly(SizeConfiguration.getDefaultInstance(), // only split apk
    compressedApkSize);
    assertThat(configurationSizes.getMaxSizeConfigurationMap()).containsExactly(SizeConfiguration.getDefaultInstance(), // only split apk
    compressedApkSize);
}
Also used : Variant(com.android.bundle.Commands.Variant) ApksArchiveHelpers.standaloneVariant(com.android.tools.build.bundletool.testing.ApksArchiveHelpers.standaloneVariant) ApksArchiveHelpers.createVariant(com.android.tools.build.bundletool.testing.ApksArchiveHelpers.createVariant) Path(java.nio.file.Path) ZipPath(com.android.tools.build.bundletool.model.ZipPath) ConfigurationSizes(com.android.tools.build.bundletool.model.ConfigurationSizes) ZipBuilder(com.android.tools.build.bundletool.io.ZipBuilder) Test(org.junit.Test)

Example 10 with ConfigurationSizes

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

the class ConfigurationSizesMergerTest method merge_defaultConfiguration.

@Test
public void merge_defaultConfiguration() throws Exception {
    ConfigurationSizes configurationSizes1 = ConfigurationSizes.create(ImmutableMap.of(SizeConfiguration.getDefaultInstance(), 10L), ImmutableMap.of(SizeConfiguration.getDefaultInstance(), 20L));
    ConfigurationSizes configurationSizes2 = ConfigurationSizes.create(ImmutableMap.of(SizeConfiguration.getDefaultInstance(), 30L), ImmutableMap.of(SizeConfiguration.getDefaultInstance(), 40L));
    ConfigurationSizes mergedConfigurationSizes = ConfigurationSizesMerger.merge(configurationSizes1, configurationSizes2);
    assertThat(mergedConfigurationSizes.getMinSizeConfigurationMap()).containsExactly(SizeConfiguration.getDefaultInstance(), 40L);
    assertThat(mergedConfigurationSizes.getMaxSizeConfigurationMap()).containsExactly(SizeConfiguration.getDefaultInstance(), 60L);
}
Also used : ConfigurationSizes(com.android.tools.build.bundletool.model.ConfigurationSizes) Test(org.junit.Test)

Aggregations

ConfigurationSizes (com.android.tools.build.bundletool.model.ConfigurationSizes)28 Test (org.junit.Test)27 Variant (com.android.bundle.Commands.Variant)20 ApksArchiveHelpers.createVariant (com.android.tools.build.bundletool.testing.ApksArchiveHelpers.createVariant)19 ApksArchiveHelpers.standaloneVariant (com.android.tools.build.bundletool.testing.ApksArchiveHelpers.standaloneVariant)19 ZipPath (com.android.tools.build.bundletool.model.ZipPath)10 Path (java.nio.file.Path)5 AssetSliceSet (com.android.bundle.Commands.AssetSliceSet)3 BuildApksResult (com.android.bundle.Commands.BuildApksResult)3 VariantTargeting (com.android.bundle.Targeting.VariantTargeting)3 ZipBuilder (com.android.tools.build.bundletool.io.ZipBuilder)3 ApksArchiveHelpers.createAssetSliceSet (com.android.tools.build.bundletool.testing.ApksArchiveHelpers.createAssetSliceSet)3 AssetModuleSizeAggregator (com.android.tools.build.bundletool.device.AssetModuleSizeAggregator)1 VariantMatcher (com.android.tools.build.bundletool.device.VariantMatcher)1 VariantTotalSizeAggregator (com.android.tools.build.bundletool.device.VariantTotalSizeAggregator)1 SizeConfiguration (com.android.tools.build.bundletool.model.SizeConfiguration)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1