use of com.android.bundle.Commands.Variant in project bundletool by google.
the class ApkSerializerManager method serializeSdkApkSetContent.
private BuildSdkApksResult serializeSdkApkSetContent(Path outputDirectory, GeneratedApks generatedApks) {
ImmutableList<Variant> allVariantsWithTargeting = serializeApks(outputDirectory, generatedApks, /* deviceSpec= */
Optional.empty());
SdkBundle sdkBundle = (SdkBundle) bundle;
return BuildSdkApksResult.newBuilder().setPackageName(sdkBundle.getPackageName()).addAllVariant(allVariantsWithTargeting).setBundletool(Bundletool.newBuilder().setVersion(BundleToolVersion.getCurrentVersion().toString())).setVersion(SdkVersionInformation.newBuilder().setVersionCode(sdkBundle.getVersionCode()).setMajor(Long.parseLong(sdkBundle.getMajorVersion())).setPatch(Long.parseLong(sdkBundle.getPatchVersion())).build()).build();
}
use of com.android.bundle.Commands.Variant in project bundletool by google.
the class ApkSizeUtilsTest method multipleVariants_withUncompressedEntries.
@Test
public void multipleVariants_withUncompressedEntries() throws Exception {
ZipPath apkOne = ZipPath.create("apk_one.apk");
ZipPath apkTwo = ZipPath.create("apk_two.apk");
ImmutableList<Variant> variants = ImmutableList.of(createVariantForSingleSplitApk(variantSdkTargeting(sdkVersionFrom(21), ImmutableSet.of(sdkVersionFrom(23))), ApkTargeting.getDefaultInstance(), apkOne), createVariantForSingleSplitApk(variantSdkTargeting(sdkVersionFrom(23), ImmutableSet.of(sdkVersionFrom(21))), ApkTargeting.getDefaultInstance(), apkTwo));
ZipBuilder archiveBuilder = new ZipBuilder();
archiveBuilder.addFileWithContent(ZipPath.create(apkOne.toString()), DUMMY_BYTES);
archiveBuilder.addFileWithContent(ZipPath.create(apkTwo.toString()), DUMMY_BYTES, // APK stored uncompressed in the APKs zip.
EntryOption.UNCOMPRESSED);
archiveBuilder.addFileWithProtoContent(ZipPath.create("toc.pb"), BuildApksResult.newBuilder().addAllVariant(variants).build());
Path apksArchiveFile = archiveBuilder.writeTo(tmpDir.resolve("bundle.apks"));
ImmutableMap<String, Long> sizeByApkPaths = getVariantCompressedSizeByApkPaths(variants, apksArchiveFile);
assertThat(sizeByApkPaths.keySet()).containsExactly("apk_one.apk", "apk_two.apk");
long apkOneSize = sizeByApkPaths.get("apk_one.apk");
long apkTwoSize = sizeByApkPaths.get("apk_two.apk");
// Apks should have size at least 20. Gzip Header(10 bytes), deflated data (Min 2 Bytes for
// empty file), 8 bytes footer.
assertThat(apkOneSize).isGreaterThan(20L);
assertThat(apkTwoSize).isGreaterThan(20L);
assertThat(apkOneSize).isEqualTo(apkTwoSize);
}
use of com.android.bundle.Commands.Variant in project bundletool by google.
the class BuildSdkApksManagerTest method sdkManifestMutation_patchVersionNotSet_defaultPatchVersionAdded.
@Test
public void sdkManifestMutation_patchVersionNotSet_defaultPatchVersionAdded() throws Exception {
SdkBundle sdkBundle = new SdkBundleBuilder().setModule(new BundleModuleBuilder("base").setManifest(androidManifest(PACKAGE_NAME, withSdkLibraryElement("20"))).build()).build();
execute(sdkBundle);
ZipFile apkSetFile = new ZipFile(outputFilePath.toFile());
BuildSdkApksResult result = extractTocFromSdkApkSetFile(apkSetFile, tmpDir);
Variant variant = result.getVariant(0);
ApkDescription apkDescription = variant.getApkSet(0).getApkDescription(0);
File apkFile = extractFromApkSetFile(apkSetFile, apkDescription.getPath(), tmpDir);
AndroidManifest manifest = extractAndroidManifest(apkFile, tmpDir);
assertThat(manifest.getMetadataValue(SDK_PATCH_VERSION_ATTRIBUTE_NAME)).hasValue(DEFAULT_SDK_PATCH_VERSION);
}
use of com.android.bundle.Commands.Variant in project bundletool by google.
the class GetSizeCommandTest method getSizeTotalInternal_withDimensionsAndDeviceSpec.
@Test
public void getSizeTotalInternal_withDimensionsAndDeviceSpec() throws Exception {
Variant lVariant = createVariant(lPlusVariantTargeting(), createSplitApkSet(/* moduleName= */
"base", createMasterApkDescription(ApkTargeting.getDefaultInstance(), ZipPath.create("base-master.apk")), createApkDescription(apkLanguageTargeting("jp"), ZipPath.create("base-jp.apk"), /* isMasterSplit= */
false), createApkDescription(apkLanguageTargeting("fr"), ZipPath.create("base-fr.apk"), /* isMasterSplit= */
false), createApkDescription(apkDensityTargeting(HDPI, ImmutableSet.of(LDPI)), ZipPath.create("base-hdpi.apk"), /* isMasterSplit= */
false), createApkDescription(apkDensityTargeting(LDPI, ImmutableSet.of(HDPI)), ZipPath.create("base-ldpi.apk"), /* isMasterSplit= */
false), createApkDescription(apkAbiTargeting(ARM64_V8A, ImmutableSet.of(ARMEABI_V7A)), ZipPath.create("base-arm64_v8a.apk"), /* isMasterSplit= */
false), createApkDescription(apkAbiTargeting(ARMEABI_V7A, ImmutableSet.of(ARM64_V8A)), ZipPath.create("base-armeabi_v7a.apk"), /* isMasterSplit= */
false)));
BuildApksResult tableOfContentsProto = BuildApksResult.newBuilder().setBundletool(Bundletool.newBuilder().setVersion(BundleToolVersion.getCurrentVersion().toString())).addVariant(lVariant).build();
Path apksArchiveFile = createApksArchiveFile(tableOfContentsProto, tmpDir.resolve("bundle.apks"));
ConfigurationSizes configurationSizes = GetSizeCommand.builder().setGetSizeSubCommand(GetSizeSubcommand.TOTAL).setApksArchivePath(apksArchiveFile).setDeviceSpec(DeviceSpec.newBuilder().setSdkVersion(21).setScreenDensity(125).addSupportedLocales("jp").build()).setDimensions(ImmutableSet.of(Dimension.SDK, Dimension.ABI, Dimension.LANGUAGE, Dimension.SCREEN_DENSITY)).build().getSizeTotalInternal();
assertThat(configurationSizes.getMinSizeConfigurationMap()).containsExactly(SizeConfiguration.builder().setAbi("armeabi-v7a").setLocale("jp").setScreenDensity("125").setSdkVersion("21").build(), 4 * compressedApkSize, SizeConfiguration.builder().setAbi("arm64-v8a").setLocale("jp").setScreenDensity("125").setSdkVersion("21").build(), 4 * compressedApkSize);
assertThat(configurationSizes.getMaxSizeConfigurationMap()).containsExactly(SizeConfiguration.builder().setAbi("armeabi-v7a").setLocale("jp").setScreenDensity("125").setSdkVersion("21").build(), 4 * compressedApkSize, SizeConfiguration.builder().setAbi("arm64-v8a").setLocale("jp").setScreenDensity("125").setSdkVersion("21").build(), 4 * compressedApkSize);
}
use of com.android.bundle.Commands.Variant in project bundletool by google.
the class GetSizeCommandTest method getSizeTotal_withDeviceTier.
@Test
public void getSizeTotal_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.DEVICE_TIER, Dimension.SDK)).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", "21-", "0", 2 * compressedApkSize, 2 * compressedApkSize), String.format("%s,%s,%d,%d", "21-", "1", 2 * compressedApkSize, 2 * compressedApkSize));
}
Aggregations