Search in sources :

Example 1 with AssetSliceSet

use of com.android.bundle.Commands.AssetSliceSet in project bundletool by google.

the class AssetModuleSizeAggregatorTest method getSize_singleAssetModule_noTargeting.

@Test
public void getSize_singleAssetModule_noTargeting() throws Exception {
    ImmutableList<AssetSliceSet> assetModules = ImmutableList.of(createAssetSliceSet("asset1", DeliveryType.INSTALL_TIME, createMasterApkDescription(ApkTargeting.getDefaultInstance(), ZipPath.create("asset1-master.apk"))));
    VariantTargeting variantTargeting = VariantTargeting.getDefaultInstance();
    ImmutableMap<String, Long> sizeByApkPaths = ImmutableMap.of("asset1-master.apk", 10L);
    ConfigurationSizes configurationSizes = new AssetModuleSizeAggregator(assetModules, variantTargeting, sizeByApkPaths, getSizeCommand.build()).getSize();
    assertThat(configurationSizes.getMinSizeConfigurationMap()).containsExactly(SizeConfiguration.getDefaultInstance(), 10L);
    assertThat(configurationSizes.getMaxSizeConfigurationMap()).containsExactly(SizeConfiguration.getDefaultInstance(), 10L);
}
Also used : ConfigurationSizes(com.android.tools.build.bundletool.model.ConfigurationSizes) VariantTargeting(com.android.bundle.Targeting.VariantTargeting) ApksArchiveHelpers.createAssetSliceSet(com.android.tools.build.bundletool.testing.ApksArchiveHelpers.createAssetSliceSet) AssetSliceSet(com.android.bundle.Commands.AssetSliceSet) Test(org.junit.Test)

Example 2 with AssetSliceSet

use of com.android.bundle.Commands.AssetSliceSet in project bundletool by google.

the class AssetModuleSizeAggregatorTest method getSize_multipleAssetModules_withTargeting.

@Test
public void getSize_multipleAssetModules_withTargeting() throws Exception {
    ImmutableList<AssetSliceSet> assetModules = ImmutableList.of(ASSET_MODULE_1, ASSET_MODULE_2);
    VariantTargeting variantTargeting = variantSdkTargeting(21);
    ConfigurationSizes configurationSizes = new AssetModuleSizeAggregator(assetModules, variantTargeting, SIZE_BY_APK_PATHS, getSizeCommand.setDimensions(ImmutableSet.of(TEXTURE_COMPRESSION_FORMAT)).build()).getSize();
    assertThat(configurationSizes.getMinSizeConfigurationMap()).containsExactly(SizeConfiguration.builder().setTextureCompressionFormat("etc2").build(), ASSET_1_MASTER_SIZE + ASSET_1_ETC2_SIZE + ASSET_2_MASTER_SIZE + ASSET_2_ETC2_SIZE, SizeConfiguration.builder().setTextureCompressionFormat("astc").build(), ASSET_1_MASTER_SIZE + ASSET_1_ASTC_SIZE + ASSET_2_MASTER_SIZE + ASSET_2_ASTC_SIZE);
    assertThat(configurationSizes.getMaxSizeConfigurationMap()).containsExactly(SizeConfiguration.builder().setTextureCompressionFormat("etc2").build(), ASSET_1_MASTER_SIZE + ASSET_1_ETC2_SIZE + ASSET_2_MASTER_SIZE + ASSET_2_ETC2_SIZE, SizeConfiguration.builder().setTextureCompressionFormat("astc").build(), ASSET_1_MASTER_SIZE + ASSET_1_ASTC_SIZE + ASSET_2_MASTER_SIZE + ASSET_2_ASTC_SIZE);
}
Also used : ConfigurationSizes(com.android.tools.build.bundletool.model.ConfigurationSizes) VariantTargeting(com.android.bundle.Targeting.VariantTargeting) ApksArchiveHelpers.createAssetSliceSet(com.android.tools.build.bundletool.testing.ApksArchiveHelpers.createAssetSliceSet) AssetSliceSet(com.android.bundle.Commands.AssetSliceSet) Test(org.junit.Test)

Example 3 with AssetSliceSet

use of com.android.bundle.Commands.AssetSliceSet in project bundletool by google.

the class GetSizeCommandTest method getSizeTotal_withAssetModulesAndDeviceSpec.

@Test
public void getSizeTotal_withAssetModulesAndDeviceSpec() 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)));
    AssetSliceSet assetModule = createAssetSliceSet(/* moduleName= */
    "asset1", DeliveryType.INSTALL_TIME, createMasterApkDescription(ApkTargeting.getDefaultInstance(), ZipPath.create("asset1-master.apk")), createApkDescription(apkTextureTargeting(ETC2, ImmutableSet.of(ASTC)), ZipPath.create("asset1-tcf_etc2.apk"), /* isMasterSplit= */
    false), createApkDescription(apkTextureTargeting(ASTC, ImmutableSet.of(ETC2)), ZipPath.create("asset1-tcf_astc.apk"), /* isMasterSplit= */
    false));
    BuildApksResult tableOfContentsProto = BuildApksResult.newBuilder().setBundletool(Bundletool.newBuilder().setVersion(BundleToolVersion.getCurrentVersion().toString())).addVariant(lVariant).addAssetSliceSet(assetModule).build();
    Path apksArchiveFile = createApksArchiveFile(tableOfContentsProto, tmpDir.resolve("bundle.apks"));
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    GetSizeCommand.builder().setGetSizeSubCommand(GetSizeSubcommand.TOTAL).setApksArchivePath(apksArchiveFile).setDimensions(ImmutableSet.of(Dimension.ABI, Dimension.TEXTURE_COMPRESSION_FORMAT, Dimension.SDK)).setDeviceSpec(DeviceSpec.newBuilder().setSdkVersion(25).addSupportedAbis("x86").addGlExtensions("GL_KHR_texture_compression_astc_ldr").build()).build().getSizeTotal(new PrintStream(outputStream));
    assertThat(new String(outputStream.toByteArray(), UTF_8)).isEqualTo("SDK,ABI,TEXTURE_COMPRESSION_FORMAT,MIN,MAX" + CRLF + String.format("%s,%s,%s,%d,%d", "25", "x86", "astc", 4 * compressedApkSize, 4 * compressedApkSize) + CRLF);
}
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) PrintStream(java.io.PrintStream) BuildApksResult(com.android.bundle.Commands.BuildApksResult) ApksArchiveHelpers.createAssetSliceSet(com.android.tools.build.bundletool.testing.ApksArchiveHelpers.createAssetSliceSet) AssetSliceSet(com.android.bundle.Commands.AssetSliceSet) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 4 with AssetSliceSet

use of com.android.bundle.Commands.AssetSliceSet in project bundletool by google.

the class GetSizeCommandTest method getSizeTotal_withAssetModulesAndMultipleVariants.

@Test
public void getSizeTotal_withAssetModulesAndMultipleVariants() throws Exception {
    Variant lVariant = createVariant(lPlusVariantTargeting(), createSplitApkSet(/* moduleName= */
    "base", createMasterApkDescription(ApkTargeting.getDefaultInstance(), ZipPath.create("base-master.apk"))));
    Variant nVariant = createVariant(variantSdkTargeting(24), createSplitApkSet(/* moduleName= */
    "base", createMasterApkDescription(ApkTargeting.getDefaultInstance(), ZipPath.create("base-master_2.apk"))));
    AssetSliceSet assetModule = createAssetSliceSet(/* moduleName= */
    "asset1", DeliveryType.INSTALL_TIME, createMasterApkDescription(apkSdkTargeting(sdkVersionFrom(21)), ZipPath.create("asset1-master.apk")), createApkDescription(mergeApkTargeting(apkTextureTargeting(ETC2, ImmutableSet.of(ASTC)), apkSdkTargeting(sdkVersionFrom(21))), ZipPath.create("asset1-tcf_etc2.apk"), /* isMasterSplit= */
    false), createApkDescription(mergeApkTargeting(apkTextureTargeting(ASTC, ImmutableSet.of(ETC2)), apkSdkTargeting(sdkVersionFrom(21))), ZipPath.create("asset1-tcf_astc.apk"), /* isMasterSplit= */
    false));
    BuildApksResult tableOfContentsProto = BuildApksResult.newBuilder().setBundletool(Bundletool.newBuilder().setVersion(BundleToolVersion.getCurrentVersion().toString())).addVariant(lVariant).addVariant(nVariant).addAssetSliceSet(assetModule).build();
    Path apksArchiveFile = createApksArchiveFile(tableOfContentsProto, tmpDir.resolve("bundle.apks"));
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    GetSizeCommand.builder().setGetSizeSubCommand(GetSizeSubcommand.TOTAL).setApksArchivePath(apksArchiveFile).setDimensions(ImmutableSet.of(Dimension.TEXTURE_COMPRESSION_FORMAT, Dimension.ABI, Dimension.SDK)).build().getSizeTotal(new PrintStream(outputStream));
    assertThat(new String(outputStream.toByteArray(), UTF_8).split(CRLF)).asList().containsExactly("SDK,ABI,TEXTURE_COMPRESSION_FORMAT,MIN,MAX", String.format("%s,,%s,%d,%d", "21-", "etc2", 3 * compressedApkSize, 3 * compressedApkSize), String.format("%s,,%s,%d,%d", "21-", "astc", 3 * compressedApkSize, 3 * compressedApkSize), String.format("%s,,%s,%d,%d", "24-", "etc2", 3 * compressedApkSize, 3 * compressedApkSize), String.format("%s,,%s,%d,%d", "24-", "astc", 3 * compressedApkSize, 3 * 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) PrintStream(java.io.PrintStream) BuildApksResult(com.android.bundle.Commands.BuildApksResult) ApksArchiveHelpers.createAssetSliceSet(com.android.tools.build.bundletool.testing.ApksArchiveHelpers.createAssetSliceSet) AssetSliceSet(com.android.bundle.Commands.AssetSliceSet) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 5 with AssetSliceSet

use of com.android.bundle.Commands.AssetSliceSet in project bundletool by google.

the class GetSizeCommandTest method getSizeTotal_withAssetModules.

@Test
public void getSizeTotal_withAssetModules() 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)));
    AssetSliceSet assetModule = createAssetSliceSet(/* moduleName= */
    "asset1", DeliveryType.INSTALL_TIME, createMasterApkDescription(ApkTargeting.getDefaultInstance(), ZipPath.create("asset1-master.apk")), createApkDescription(apkTextureTargeting(ETC2, ImmutableSet.of(ASTC)), ZipPath.create("asset1-tcf_etc2.apk"), /* isMasterSplit= */
    false), createApkDescription(apkTextureTargeting(ASTC, ImmutableSet.of(ETC2)), ZipPath.create("asset1-tcf_astc.apk"), /* isMasterSplit= */
    false));
    // Only install-time asset modules are counted towards the size.
    AssetSliceSet ignoredOnDemandAssetModule = createAssetSliceSet(/* moduleName= */
    "asset2", DeliveryType.ON_DEMAND, createMasterApkDescription(ApkTargeting.getDefaultInstance(), ZipPath.create("asset2-master.apk")));
    BuildApksResult tableOfContentsProto = BuildApksResult.newBuilder().setBundletool(Bundletool.newBuilder().setVersion(BundleToolVersion.getCurrentVersion().toString())).addVariant(lVariant).addAssetSliceSet(assetModule).addAssetSliceSet(ignoredOnDemandAssetModule).build();
    Path apksArchiveFile = createApksArchiveFile(tableOfContentsProto, tmpDir.resolve("bundle.apks"));
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    GetSizeCommand.builder().setGetSizeSubCommand(GetSizeSubcommand.TOTAL).setApksArchivePath(apksArchiveFile).setDimensions(ImmutableSet.of(Dimension.ABI, Dimension.TEXTURE_COMPRESSION_FORMAT, Dimension.SDK)).build().getSizeTotal(new PrintStream(outputStream));
    assertThat(new String(outputStream.toByteArray(), UTF_8).split(CRLF)).asList().containsExactly("SDK,ABI,TEXTURE_COMPRESSION_FORMAT,MIN,MAX", String.format("%s,%s,%s,%d,%d", "21-", "x86_64", "astc", 4 * compressedApkSize, 4 * compressedApkSize), String.format("%s,%s,%s,%d,%d", "21-", "x86_64", "etc2", 4 * compressedApkSize, 4 * compressedApkSize), String.format("%s,%s,%s,%d,%d", "21-", "x86", "astc", 4 * compressedApkSize, 4 * compressedApkSize), String.format("%s,%s,%s,%d,%d", "21-", "x86", "etc2", 4 * compressedApkSize, 4 * 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) PrintStream(java.io.PrintStream) BuildApksResult(com.android.bundle.Commands.BuildApksResult) ApksArchiveHelpers.createAssetSliceSet(com.android.tools.build.bundletool.testing.ApksArchiveHelpers.createAssetSliceSet) AssetSliceSet(com.android.bundle.Commands.AssetSliceSet) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Aggregations

AssetSliceSet (com.android.bundle.Commands.AssetSliceSet)9 Test (org.junit.Test)9 BuildApksResult (com.android.bundle.Commands.BuildApksResult)6 Variant (com.android.bundle.Commands.Variant)6 Path (java.nio.file.Path)6 VariantTargeting (com.android.bundle.Targeting.VariantTargeting)5 ZipPath (com.android.tools.build.bundletool.model.ZipPath)5 ApksArchiveHelpers.createAssetSliceSet (com.android.tools.build.bundletool.testing.ApksArchiveHelpers.createAssetSliceSet)4 ApkDescription (com.android.bundle.Commands.ApkDescription)3 ApkSet (com.android.bundle.Commands.ApkSet)3 ARM64_V8A (com.android.bundle.Targeting.Abi.AbiAlias.ARM64_V8A)3 ARMEABI_V7A (com.android.bundle.Targeting.Abi.AbiAlias.ARMEABI_V7A)3 ApkTargeting (com.android.bundle.Targeting.ApkTargeting)3 AppBundleSerializer (com.android.tools.build.bundletool.io.AppBundleSerializer)3 AndroidManifest (com.android.tools.build.bundletool.model.AndroidManifest)3 AppBundle (com.android.tools.build.bundletool.model.AppBundle)3 InvalidBundleException (com.android.tools.build.bundletool.model.exceptions.InvalidBundleException)3 ResultUtils.splitApkVariants (com.android.tools.build.bundletool.model.utils.ResultUtils.splitApkVariants)3 ResultUtils.standaloneApkVariants (com.android.tools.build.bundletool.model.utils.ResultUtils.standaloneApkVariants)3 ApkSetUtils.extractFromApkSetFile (com.android.tools.build.bundletool.testing.ApkSetUtils.extractFromApkSetFile)3