Search in sources :

Example 66 with Variant

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

the class GetSizeCommandTest method getSizeTotal_withDeviceTier_withDeviceTier.

@Test
public void getSizeTotal_withDeviceTier_withDeviceTier() throws Exception {
    Variant lVariant = createVariant(lPlusVariantTargeting(), createSplitApkSet(/* moduleName= */
    "base", createMasterApkDescription(ApkTargeting.getDefaultInstance(), ZipPath.create("base-master.apk")), splitApkDescription(apkDeviceTierTargeting(deviceTierTargeting(/* value= */
    0, /* alternatives= */
    ImmutableList.of(1))), ZipPath.create("base-tier_0.apk")), splitApkDescription(apkDeviceTierTargeting(deviceTierTargeting(/* value= */
    1, /* alternatives= */
    ImmutableList.of(0))), ZipPath.create("base-tier_1.apk"))));
    BuildApksResult tableOfContentsProto = BuildApksResult.newBuilder().setBundletool(Bundletool.newBuilder().setVersion(BundleToolVersion.getCurrentVersion().toString())).addVariant(lVariant).build();
    Path apksArchiveFile = createApksArchiveFile(tableOfContentsProto, tmpDir.resolve("bundle.apks"));
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    GetSizeCommand.builder().setGetSizeSubCommand(GetSizeSubcommand.TOTAL).setApksArchivePath(apksArchiveFile).setDimensions(ImmutableSet.of(Dimension.SDK, Dimension.DEVICE_TIER)).setDeviceSpec(DeviceSpec.newBuilder().setSdkVersion(25).setDeviceTier(Int32Value.of(1)).build()).build().getSizeTotal(new PrintStream(outputStream));
    assertThat(new String(outputStream.toByteArray(), UTF_8).split(CRLF)).asList().containsExactly("SDK,DEVICE_TIER,MIN,MAX", String.format("%s,%s,%d,%d", "25", "1", 2 * compressedApkSize, 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) PrintStream(java.io.PrintStream) BuildApksResult(com.android.bundle.Commands.BuildApksResult) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 67 with Variant

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

the class GetSizeCommandTest method getSizeTotal_withInstant.

@Test
public void getSizeTotal_withInstant() throws Exception {
    Variant lInstantVariant = createVariant(variantSdkTargeting(sdkVersionFrom(21), ImmutableSet.of(SdkVersion.getDefaultInstance())), createInstantApkSet("base", ApkTargeting.getDefaultInstance(), ZipPath.create("base-master.apk")), createInstantApkSet("instant", ApkTargeting.getDefaultInstance(), ZipPath.create("instant-master.apk")));
    Variant lSplitVariant = createVariant(variantSdkTargeting(sdkVersionFrom(21), ImmutableSet.of(SdkVersion.getDefaultInstance())), createSplitApkSet("other", createMasterApkDescription(ApkTargeting.getDefaultInstance(), ZipPath.create("other-master.apk"))));
    Variant preLVariant = standaloneVariant(mergeVariantTargeting(variantSdkTargeting(sdkVersionFrom(15), ImmutableSet.of(sdkVersionFrom(21)))), ApkTargeting.getDefaultInstance(), ZipPath.create("preL.apk"));
    BuildApksResult tableOfContentsProto = BuildApksResult.newBuilder().setBundletool(Bundletool.newBuilder().setVersion(BundleToolVersion.getCurrentVersion().toString())).addVariant(lInstantVariant).addVariant(lSplitVariant).addVariant(preLVariant).build();
    Path apksArchiveFile = createApksArchiveFile(tableOfContentsProto, tmpDir.resolve("bundle.apks"));
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    GetSizeCommand.builder().setGetSizeSubCommand(GetSizeSubcommand.TOTAL).setApksArchivePath(apksArchiveFile).setInstant(true).build().getSizeTotal(new PrintStream(outputStream));
    // only instant split variant is selected
    assertThat(new String(outputStream.toByteArray(), UTF_8)).isEqualTo("MIN,MAX" + CRLF + String.format("%d,%d", 2 * compressedApkSize, 2 * 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) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 68 with Variant

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

the class GetSizeCommandTest method getSizeTotal_noDimensions_prettyPrint.

@Test
public void getSizeTotal_noDimensions_prettyPrint() 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)), createSplitApkSet(/* moduleName= */
    "feature1", createMasterApkDescription(ApkTargeting.getDefaultInstance(), ZipPath.create("base-feature1.apk"))));
    Variant preLVariant = standaloneVariant(mergeVariantTargeting(variantSdkTargeting(sdkVersionFrom(15), ImmutableSet.of(sdkVersionFrom(21)))), 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"));
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    GetSizeCommand.builder().setGetSizeSubCommand(GetSizeSubcommand.TOTAL).setApksArchivePath(apksArchiveFile).setHumanReadableSizes(true).build().getSizeTotal(new PrintStream(outputStream));
    assertThat(new String(outputStream.toByteArray(), UTF_8)).isEqualTo("MIN,MAX" + CRLF + String.format("%d B,%d B", compressedApkSize, 3 * 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) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 69 with Variant

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

the class GetSizeCommandTest method getSizeTotalInternal_multipleStandaloneVariant.

@Test
public void getSizeTotalInternal_multipleStandaloneVariant() throws Exception {
    Variant preLLdpiVariant = standaloneVariant(mergeVariantTargeting(variantSdkTargeting(sdkVersionFrom(1), ImmutableSet.of(sdkVersionFrom(21))), variantDensityTargeting(LDPI, ImmutableSet.of(MDPI))), ApkTargeting.getDefaultInstance(), ZipPath.create("preL-ldpi.apk"));
    Variant preLMdpiVariant = standaloneVariant(mergeVariantTargeting(variantSdkTargeting(sdkVersionFrom(1), ImmutableSet.of(sdkVersionFrom(21))), variantDensityTargeting(MDPI, ImmutableSet.of(LDPI))), ApkTargeting.getDefaultInstance(), ZipPath.create("preL-mdpi.apk"));
    ZipBuilder archiveBuilder = new ZipBuilder();
    archiveBuilder.addFileWithContent(ZipPath.create("preL-ldpi.apk"), new byte[1000]);
    archiveBuilder.addFileWithContent(ZipPath.create("preL-mdpi.apk"), new byte[10]);
    archiveBuilder.addFileWithProtoContent(ZipPath.create("toc.pb"), BuildApksResult.newBuilder().setBundletool(Bundletool.newBuilder().setVersion(BundleToolVersion.getCurrentVersion().toString())).addVariant(preLLdpiVariant).addVariant(preLMdpiVariant).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())).isLessThan(compressedApkSize);
    assertThat(configurationSizes.getMaxSizeConfigurationMap().keySet()).containsExactly(SizeConfiguration.getDefaultInstance());
    assertThat(configurationSizes.getMaxSizeConfigurationMap().get(SizeConfiguration.getDefaultInstance())).isGreaterThan(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 70 with Variant

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

the class GetSizeCommandTest method getSizeTotal_noDimensions.

@Test
public void getSizeTotal_noDimensions() 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)), createSplitApkSet(/* moduleName= */
    "feature1", createMasterApkDescription(ApkTargeting.getDefaultInstance(), ZipPath.create("base-feature1.apk"))));
    Variant preLVariant = standaloneVariant(mergeVariantTargeting(variantSdkTargeting(sdkVersionFrom(15), ImmutableSet.of(sdkVersionFrom(21)))), 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"));
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    GetSizeCommand.builder().setGetSizeSubCommand(GetSizeSubcommand.TOTAL).setApksArchivePath(apksArchiveFile).build().getSizeTotal(new PrintStream(outputStream));
    assertThat(new String(outputStream.toByteArray(), UTF_8)).isEqualTo("MIN,MAX" + CRLF + String.format("%d,%d", compressedApkSize, 3 * 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) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Aggregations

Variant (com.android.bundle.Commands.Variant)134 Test (org.junit.Test)130 BuildApksResult (com.android.bundle.Commands.BuildApksResult)100 ZipPath (com.android.tools.build.bundletool.model.ZipPath)82 Path (java.nio.file.Path)80 ZipFile (java.util.zip.ZipFile)79 AppBundle (com.android.tools.build.bundletool.model.AppBundle)66 AppBundleBuilder (com.android.tools.build.bundletool.testing.AppBundleBuilder)66 ApkSet (com.android.bundle.Commands.ApkSet)63 ApkDescription (com.android.bundle.Commands.ApkDescription)60 ApkSetUtils.extractFromApkSetFile (com.android.tools.build.bundletool.testing.ApkSetUtils.extractFromApkSetFile)59 File (java.io.File)59 AndroidManifest (com.android.tools.build.bundletool.model.AndroidManifest)56 AssetSliceSet (com.android.bundle.Commands.AssetSliceSet)55 ApkSetUtils.extractTocFromApkSetFile (com.android.tools.build.bundletool.testing.ApkSetUtils.extractTocFromApkSetFile)55 CodeRelatedFile (com.android.bundle.CodeTransparencyOuterClass.CodeRelatedFile)54 ApkSetUtils.parseTocFromFile (com.android.tools.build.bundletool.testing.ApkSetUtils.parseTocFromFile)54 ResourceTableBuilder (com.android.tools.build.bundletool.testing.ResourceTableBuilder)54 ImmutableSet (com.google.common.collect.ImmutableSet)54 ApkVerifier (com.android.apksig.ApkVerifier)53