Search in sources :

Example 71 with Variant

use of com.android.bundle.Commands.Variant 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)

Example 72 with Variant

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

the class VariantMatcherTest method getAllMatchingVariants_partialDeviceSpec.

@Test
public void getAllMatchingVariants_partialDeviceSpec() {
    ZipPath standaloneArmXxxhdpiApk = ZipPath.create("standalone-arm.xxxhdpi.apk");
    ZipPath baseMasterSplitApk = ZipPath.create("base-master.apk");
    ZipPath baseArmSplitApk = ZipPath.create("base-arm.apk");
    ZipPath screenXxxhdpiApk = ZipPath.create("screen-xxxhdpi.apk");
    Variant standaloneVariant = standaloneVariant(mergeVariantTargeting(variantSdkTargeting(sdkVersionFrom(1), ImmutableSet.of(sdkVersionFrom(21))), variantAbiTargeting(ARMEABI, ImmutableSet.of(X86)), variantDensityTargeting(XXXHDPI, ImmutableSet.of(MDPI))), mergeApkTargeting(apkAbiTargeting(ARMEABI, ImmutableSet.of(X86)), apkDensityTargeting(XXXHDPI, ImmutableSet.of(MDPI))), standaloneArmXxxhdpiApk);
    Variant splitVariant = createVariant(variantSdkTargeting(sdkVersionFrom(21), ImmutableSet.of(sdkVersionFrom(1))), splitApkSet(/* moduleName= */
    "base", splitApkDescription(ApkTargeting.getDefaultInstance(), baseMasterSplitApk), splitApkDescription(apkAbiTargeting(ARMEABI, ImmutableSet.of(X86)), baseArmSplitApk)), splitApkSet(/* moduleName= */
    "screen", splitApkDescription(apkDensityTargeting(XXXHDPI, ImmutableSet.of(MDPI)), screenXxxhdpiApk)));
    ImmutableList<Variant> variants = ImmutableList.of(standaloneVariant, splitVariant);
    BuildApksResult buildApksResult = BuildApksResult.newBuilder().addAllVariant(variants).build();
    DeviceSpec preLDevice = mergeSpecs(sdkVersion(19));
    assertThat(new VariantMatcher(preLDevice).getAllMatchingVariants(buildApksResult)).containsExactly(standaloneVariant);
    DeviceSpec preLXXXHDPIDevice = mergeSpecs(sdkVersion(19), density(XXXHDPI));
    assertThat(new VariantMatcher(preLXXXHDPIDevice).getAllMatchingVariants(buildApksResult)).containsExactly(standaloneVariant);
    DeviceSpec preLX86Device = mergeSpecs(sdkVersion(19), abis("x86"));
    assertThat(new VariantMatcher(preLX86Device).getAllMatchingVariants(buildApksResult)).isEmpty();
    DeviceSpec postLDevice = mergeSpecs(sdkVersion(21));
    assertThat(new VariantMatcher(postLDevice).getAllMatchingVariants(buildApksResult)).containsExactly(splitVariant);
}
Also used : ApksArchiveHelpers.createVariant(com.android.tools.build.bundletool.testing.ApksArchiveHelpers.createVariant) Variant(com.android.bundle.Commands.Variant) ApksArchiveHelpers.multiAbiTargetingApexVariant(com.android.tools.build.bundletool.testing.ApksArchiveHelpers.multiAbiTargetingApexVariant) ApksArchiveHelpers.standaloneVariant(com.android.tools.build.bundletool.testing.ApksArchiveHelpers.standaloneVariant) DeviceSpec(com.android.bundle.Devices.DeviceSpec) BuildApksResult(com.android.bundle.Commands.BuildApksResult) ZipPath(com.android.tools.build.bundletool.model.ZipPath) Test(org.junit.Test)

Example 73 with Variant

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

the class VariantMatcherTest method getAllMatchingVariants_emptyDeviceSpecMatchesAllVariants.

@Test
public void getAllMatchingVariants_emptyDeviceSpecMatchesAllVariants() {
    ZipPath standaloneArmXxxhdpiApk = ZipPath.create("standalone-arm.xxxhdpi.apk");
    ZipPath baseMasterSplitApk = ZipPath.create("base-master.apk");
    ZipPath baseArmSplitApk = ZipPath.create("base-arm.apk");
    ZipPath screenXxxhdpiApk = ZipPath.create("screen-xxxhdpi.apk");
    ImmutableList<Variant> variants = ImmutableList.of(// Standalone ARM XXXHDPI
    standaloneVariant(mergeVariantTargeting(variantSdkTargeting(sdkVersionFrom(1), ImmutableSet.of(sdkVersionFrom(21))), variantAbiTargeting(ARMEABI, ImmutableSet.of(X86)), variantDensityTargeting(XXXHDPI, ImmutableSet.of(MDPI))), mergeApkTargeting(apkAbiTargeting(ARMEABI, ImmutableSet.of(X86)), apkDensityTargeting(XXXHDPI, ImmutableSet.of(MDPI))), standaloneArmXxxhdpiApk), // Splits L+
    createVariant(variantSdkTargeting(sdkVersionFrom(21), ImmutableSet.of(sdkVersionFrom(1))), splitApkSet(/* moduleName= */
    "base", splitApkDescription(ApkTargeting.getDefaultInstance(), baseMasterSplitApk), splitApkDescription(apkAbiTargeting(ARMEABI, ImmutableSet.of(X86)), baseArmSplitApk)), splitApkSet(/* moduleName= */
    "screen", splitApkDescription(apkDensityTargeting(XXXHDPI, ImmutableSet.of(MDPI)), screenXxxhdpiApk))));
    BuildApksResult buildApksResult = BuildApksResult.newBuilder().addAllVariant(variants).build();
    assertThat(new VariantMatcher(DeviceSpec.getDefaultInstance()).getAllMatchingVariants(buildApksResult)).isEqualTo(variants);
}
Also used : ApksArchiveHelpers.createVariant(com.android.tools.build.bundletool.testing.ApksArchiveHelpers.createVariant) Variant(com.android.bundle.Commands.Variant) ApksArchiveHelpers.multiAbiTargetingApexVariant(com.android.tools.build.bundletool.testing.ApksArchiveHelpers.multiAbiTargetingApexVariant) ApksArchiveHelpers.standaloneVariant(com.android.tools.build.bundletool.testing.ApksArchiveHelpers.standaloneVariant) BuildApksResult(com.android.bundle.Commands.BuildApksResult) ZipPath(com.android.tools.build.bundletool.model.ZipPath) Test(org.junit.Test)

Example 74 with Variant

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

the class VariantMatcherTest method getAllMatchingVariants_fullDeviceSpec.

@Test
public void getAllMatchingVariants_fullDeviceSpec() {
    ZipPath standaloneX86MdpiApk = ZipPath.create("standalone-x86.mdpi.apk");
    ZipPath baseMasterSplitApk = ZipPath.create("base-master.apk");
    ZipPath baseArmSplitApk = ZipPath.create("base-arm.apk");
    ZipPath screenXxxhdpiApk = ZipPath.create("screen-xxxhdpi.apk");
    Variant standaloneX86MdpiVariant = standaloneVariant(mergeVariantTargeting(variantSdkTargeting(sdkVersionFrom(1), ImmutableSet.of(sdkVersionFrom(21))), variantAbiTargeting(X86, ImmutableSet.of(ARMEABI)), variantDensityTargeting(MDPI, ImmutableSet.of(XXXHDPI))), mergeApkTargeting(apkAbiTargeting(X86, ImmutableSet.of(ARMEABI)), apkDensityTargeting(MDPI, ImmutableSet.of(XXXHDPI))), standaloneX86MdpiApk);
    Variant splitVariant = createVariant(variantSdkTargeting(sdkVersionFrom(21), ImmutableSet.of(sdkVersionFrom(1))), splitApkSet(/* moduleName= */
    "base", splitApkDescription(ApkTargeting.getDefaultInstance(), baseMasterSplitApk), splitApkDescription(apkAbiTargeting(ARMEABI, ImmutableSet.of(X86)), baseArmSplitApk)), splitApkSet(/* moduleName= */
    "screen", splitApkDescription(apkDensityTargeting(XXXHDPI, ImmutableSet.of(MDPI)), screenXxxhdpiApk)));
    ImmutableList<Variant> variants = ImmutableList.of(standaloneX86MdpiVariant, splitVariant);
    BuildApksResult buildApksResult = BuildApksResult.newBuilder().addAllVariant(variants).build();
    DeviceSpec preLX86MdpiDevice = mergeSpecs(sdkVersion(19), abis("x86"), density(MDPI), locales("en"));
    assertThat(new VariantMatcher(preLX86MdpiDevice).getAllMatchingVariants(buildApksResult)).containsExactly(standaloneX86MdpiVariant);
    DeviceSpec preLX86HdpiDevice = mergeSpecs(sdkVersion(19), abis("x86"), density(HDPI), locales("en"));
    assertThat(new VariantMatcher(preLX86HdpiDevice).getAllMatchingVariants(buildApksResult)).isEmpty();
    DeviceSpec postLDevice = mergeSpecs(sdkVersion(21), abis("x86"), density(MDPI), locales("en"));
    assertThat(new VariantMatcher(postLDevice).getAllMatchingVariants(buildApksResult)).containsExactly(splitVariant);
}
Also used : ApksArchiveHelpers.createVariant(com.android.tools.build.bundletool.testing.ApksArchiveHelpers.createVariant) Variant(com.android.bundle.Commands.Variant) ApksArchiveHelpers.multiAbiTargetingApexVariant(com.android.tools.build.bundletool.testing.ApksArchiveHelpers.multiAbiTargetingApexVariant) ApksArchiveHelpers.standaloneVariant(com.android.tools.build.bundletool.testing.ApksArchiveHelpers.standaloneVariant) DeviceSpec(com.android.bundle.Devices.DeviceSpec) BuildApksResult(com.android.bundle.Commands.BuildApksResult) ZipPath(com.android.tools.build.bundletool.model.ZipPath) Test(org.junit.Test)

Example 75 with Variant

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

the class VariantTotalSizeAggregatorTest method splitVariant_singleModule_multipleTargeting_withAllDeviceSpecsAndDimensions.

@Test
public void splitVariant_singleModule_multipleTargeting_withAllDeviceSpecsAndDimensions() {
    Variant lVariant = createVariant(lPlusVariantTargeting(), createSplitApkSet(/* moduleName= */
    "base", createMasterApkDescription(ApkTargeting.getDefaultInstance(), ZipPath.create("base-master.apk")), createApkDescription(apkLanguageTargeting("fr"), ZipPath.create("base-fr.apk"), /* isMasterSplit= */
    false), createApkDescription(apkLanguageTargeting("en-GB"), ZipPath.create("base-en-GB.apk"), /* isMasterSplit= */
    false), createApkDescription(apkDensityTargeting(XHDPI, ImmutableSet.of(XXHDPI)), ZipPath.create("base-xhdpi.apk"), /* isMasterSplit= */
    false), createApkDescription(apkDensityTargeting(XXHDPI, ImmutableSet.of(XHDPI)), ZipPath.create("base-xxhdpi.apk"), /* isMasterSplit= */
    false), createApkDescription(apkAbiTargeting(MIPS, ImmutableSet.of(MIPS64)), ZipPath.create("base-mips.apk"), /* isMasterSplit= */
    false), createApkDescription(apkAbiTargeting(MIPS64, ImmutableSet.of(MIPS)), ZipPath.create("base-mips64.apk"), /* isMasterSplit= */
    false)));
    ConfigurationSizes configurationSizes = new VariantTotalSizeAggregator(ImmutableMap.<String, Long>builder().put("base-master.apk", 10L).put("base-fr.apk", 1L).put("base-en-GB.apk", 2L).put("base-xhdpi.apk", 6L).put("base-xxhdpi.apk", 3L).put("base-mips.apk", 4L).put("base-mips64.apk", 5L).build(), BundleToolVersion.getCurrentVersion(), lVariant, getSizeCommand.setDimensions(ImmutableSet.of(SCREEN_DENSITY, SDK, LANGUAGE, ABI)).setDeviceSpec(mergeSpecs(locales("fr", "jp"), abis("x86", "mips"), density(XHDPI), sdkVersion(21))).build()).getSize();
    assertThat(configurationSizes.getMaxSizeConfigurationMap()).containsExactly(SizeConfiguration.builder().setSdkVersion("21").setScreenDensity("320").setLocale("fr,jp").setAbi("x86,mips").build(), 21L);
    assertThat(configurationSizes.getMinSizeConfigurationMap()).containsExactly(SizeConfiguration.builder().setSdkVersion("21").setScreenDensity("320").setLocale("fr,jp").setAbi("x86,mips").build(), 21L);
}
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)

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