Search in sources :

Example 26 with ConfigurationSizes

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

the class VariantTotalSizeAggregatorTest method getSize_standaloneVariant_withDimensionsAndWithoutDeviceSpec.

@Test
public void getSize_standaloneVariant_withDimensionsAndWithoutDeviceSpec() {
    ZipPath apk = ZipPath.create("sample.apk");
    Variant variant = standaloneVariant(mergeVariantTargeting(variantSdkTargeting(sdkVersionFrom(1), ImmutableSet.of(sdkVersionFrom(21))), variantAbiTargeting(ARMEABI_V7A, ImmutableSet.of(X86, ARM64_V8A)), variantDensityTargeting(XHDPI, ImmutableSet.of(MDPI, LDPI))), ApkTargeting.getDefaultInstance(), apk);
    ConfigurationSizes configurationSizes = new VariantTotalSizeAggregator(ImmutableMap.of("sample.apk", 20L), BundleToolVersion.getCurrentVersion(), variant, getSizeCommand.setDimensions(ImmutableSet.of(ABI, SCREEN_DENSITY, LANGUAGE, SDK)).build()).getSize();
    assertThat(configurationSizes.getMinSizeConfigurationMap()).isEqualTo(configurationSizes.getMaxSizeConfigurationMap());
    assertThat(configurationSizes.getMinSizeConfigurationMap()).containsExactly(SizeConfiguration.builder().setAbi("armeabi-v7a").setScreenDensity("XHDPI").setSdkVersion("1-20").build(), 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) ZipPath(com.android.tools.build.bundletool.model.ZipPath) Test(org.junit.Test)

Example 27 with ConfigurationSizes

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

the class ConfigurationSizesMergerTest method merge_withSubsetOfConfiguration.

@Test
public void merge_withSubsetOfConfiguration() throws Exception {
    ConfigurationSizes configurationSizes1 = ConfigurationSizes.create(ImmutableMap.of(SizeConfiguration.builder().setAbi("x86").setSdkVersion("21-").build(), 10L, SizeConfiguration.builder().setAbi("x86_64").setSdkVersion("21-").build(), 15L), ImmutableMap.of(SizeConfiguration.builder().setAbi("x86").setSdkVersion("21-").build(), 20L, SizeConfiguration.builder().setAbi("x86_64").setSdkVersion("21-").build(), 25L));
    ConfigurationSizes configurationSizes2 = ConfigurationSizes.create(ImmutableMap.of(SizeConfiguration.builder().setSdkVersion("21-").build(), 0L), ImmutableMap.of(SizeConfiguration.builder().setSdkVersion("21-").build(), 0L));
    ConfigurationSizes mergedConfigurationSizes = ConfigurationSizesMerger.merge(configurationSizes1, configurationSizes2);
    assertThat(mergedConfigurationSizes.getMinSizeConfigurationMap()).isEqualTo(configurationSizes1.getMinSizeConfigurationMap());
    assertThat(mergedConfigurationSizes.getMaxSizeConfigurationMap()).isEqualTo(configurationSizes1.getMaxSizeConfigurationMap());
}
Also used : ConfigurationSizes(com.android.tools.build.bundletool.model.ConfigurationSizes) Test(org.junit.Test)

Example 28 with ConfigurationSizes

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

the class GetSizeCommand method getSizeTotalInternal.

@VisibleForTesting
ConfigurationSizes getSizeTotalInternal() {
    BuildApksResult buildApksResult = ResultUtils.readTableOfContents(getApksArchivePath());
    ImmutableList<Variant> variants = new VariantMatcher(getDeviceSpec(), getInstant()).getAllMatchingVariants(buildApksResult);
    ImmutableMap<String, Long> variantCompressedSizeByApkPaths = getVariantCompressedSizeByApkPaths(variants, getApksArchivePath());
    ImmutableList<String> assetModuleApks = buildApksResult.getAssetSliceSetList().stream().flatMap(module -> module.getApkDescriptionList().stream()).map(ApkDescription::getPath).collect(toImmutableList());
    ImmutableMap<String, Long> assetModuleCompressedSizeByApkPaths = getCompressedSizeByApkPaths(assetModuleApks, getApksArchivePath());
    ImmutableMap<SizeConfiguration, Long> minSizeConfigurationMap = ImmutableMap.of();
    ImmutableMap<SizeConfiguration, Long> maxSizeConfigurationMap = ImmutableMap.of();
    for (Variant variant : variants) {
        ConfigurationSizes variantConfigurationSizes = new VariantTotalSizeAggregator(variantCompressedSizeByApkPaths, Version.of(buildApksResult.getBundletool().getVersion()), variant, this).getSize();
        ConfigurationSizes assetModuleConfigurationSizes = new AssetModuleSizeAggregator(buildApksResult.getAssetSliceSetList(), variant.getTargeting(), assetModuleCompressedSizeByApkPaths, this).getSize();
        ConfigurationSizes configurationSizes = ConfigurationSizesMerger.merge(variantConfigurationSizes, assetModuleConfigurationSizes);
        minSizeConfigurationMap = combineMaps(minSizeConfigurationMap, configurationSizes.getMinSizeConfigurationMap(), Math::min);
        maxSizeConfigurationMap = combineMaps(maxSizeConfigurationMap, configurationSizes.getMaxSizeConfigurationMap(), Math::max);
    }
    return ConfigurationSizes.create(minSizeConfigurationMap, maxSizeConfigurationMap);
}
Also used : BuildApksResult(com.android.bundle.Commands.BuildApksResult) VariantMatcher(com.android.tools.build.bundletool.device.VariantMatcher) AssetModuleSizeAggregator(com.android.tools.build.bundletool.device.AssetModuleSizeAggregator) Variant(com.android.bundle.Commands.Variant) ConfigurationSizes(com.android.tools.build.bundletool.model.ConfigurationSizes) VariantTotalSizeAggregator(com.android.tools.build.bundletool.device.VariantTotalSizeAggregator) SizeConfiguration(com.android.tools.build.bundletool.model.SizeConfiguration) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

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