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));
}
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);
}
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);
}
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);
}
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);
}
Aggregations