use of com.android.bundle.Commands.Variant in project bundletool by google.
the class BuildApksConnectedDeviceTest method connectedDevice_correctSplitsGenerated.
@Test
public void connectedDevice_correctSplitsGenerated() throws Exception {
fakeAdbServer = new FakeAdbServer(/* hasInitialDeviceList= */
true, ImmutableList.of(FakeDevice.fromDeviceSpec("id1", DeviceState.ONLINE, lDeviceWithDensity(DensityAlias.XHDPI))));
bundleSerializer.writeToDisk(createLdpiHdpiAppBundle(), bundlePath);
BuildApksCommand command = BuildApksCommand.builder().setBundlePath(bundlePath).setOutputFile(outputFilePath).setGenerateOnlyForConnectedDevice(true).setAdbPath(sdkDirPath.resolve("platform-tools").resolve("adb")).setAdbServer(fakeAdbServer).build();
Path apksArchive = command.execute();
BuildApksResult result;
try (ZipFile apksZipFile = new ZipFile(apksArchive.toFile())) {
assertThat(apksZipFile).containsExactlyEntries("toc.pb", "splits/base-master.apk", "splits/base-xhdpi.apk");
result = extractTocFromApkSetFile(apksZipFile, outputDir);
}
assertThat(result.getVariantList()).hasSize(1);
Variant variant = result.getVariant(0);
assertThat(variant.getApkSetList()).hasSize(1);
ApkSet apkSet = variant.getApkSet(0);
// One master and one density split.
assertThat(apkSet.getApkDescriptionList()).hasSize(2);
assertThat(apkNamesInSet(apkSet)).containsExactly("splits/base-master.apk", "splits/base-xhdpi.apk");
}
use of com.android.bundle.Commands.Variant in project bundletool by google.
the class BuildApksDeviceSpecTest method deviceSpec_correctStandaloneGenerated.
@Test
public void deviceSpec_correctStandaloneGenerated() throws Exception {
DeviceSpec deviceSpec = mergeSpecs(sdkVersion(19), abis("x86"), locales("en-US"), density(HDPI));
bundleSerializer.writeToDisk(createLdpiHdpiAppBundle(), bundlePath);
BuildApksCommand command = BuildApksCommand.builder().setBundlePath(bundlePath).setOutputFile(outputFilePath).setDeviceSpec(deviceSpec).build();
Path apksArchive = command.execute();
BuildApksResult result;
try (ZipFile apksZipFile = new ZipFile(apksArchive.toFile())) {
assertThat(apksZipFile).containsExactlyEntries("toc.pb", "standalones/standalone-hdpi.apk");
result = extractTocFromApkSetFile(apksZipFile, outputDir);
}
assertThat(result.getVariantList()).hasSize(1);
Variant variant = result.getVariant(0);
assertThat(variant.getApkSetList()).hasSize(1);
ApkSet apkSet = variant.getApkSet(0);
// One standalone APK.
assertThat(apkSet.getApkDescriptionList()).hasSize(1);
assertThat(apkNamesInSet(apkSet)).containsExactly("standalones/standalone-hdpi.apk");
}
use of com.android.bundle.Commands.Variant in project bundletool by google.
the class BuildApksConnectedDeviceTest method connectedDevice_withDeviceId_correctSplitsGenerated.
@Test
public void connectedDevice_withDeviceId_correctSplitsGenerated() throws Exception {
fakeAdbServer = new FakeAdbServer(/* hasInitialDeviceList= */
true, ImmutableList.of(FakeDevice.fromDeviceSpec("id1", DeviceState.ONLINE, lDeviceWithDensity(DensityAlias.XHDPI)), FakeDevice.fromDeviceSpec("id2", DeviceState.ONLINE, lDeviceWithDensity(DensityAlias.MDPI))));
bundleSerializer.writeToDisk(createLdpiHdpiAppBundle(), bundlePath);
// We are picking the "id2" - MDPI device.
BuildApksCommand command = BuildApksCommand.builder().setBundlePath(bundlePath).setOutputFile(outputFilePath).setGenerateOnlyForConnectedDevice(true).setAdbPath(sdkDirPath.resolve("platform-tools").resolve("adb")).setAdbServer(fakeAdbServer).setDeviceId("id2").build();
Path apksArchive = command.execute();
BuildApksResult result;
try (ZipFile apksZipFile = new ZipFile(apksArchive.toFile())) {
assertThat(apksZipFile).containsExactlyEntries("toc.pb", "splits/base-master.apk", "splits/base-mdpi.apk");
result = extractTocFromApkSetFile(apksZipFile, outputDir);
}
assertThat(result.getVariantList()).hasSize(1);
Variant variant = result.getVariant(0);
assertThat(variant.getApkSetList()).hasSize(1);
ApkSet apkSet = variant.getApkSet(0);
// One master and one density split.
assertThat(apkSet.getApkDescriptionList()).hasSize(2);
assertThat(apkNamesInSet(apkSet)).containsExactly("splits/base-master.apk", "splits/base-mdpi.apk");
}
use of com.android.bundle.Commands.Variant in project bundletool by google.
the class GetSizeCommandTest method getSizeTotal_withSelectModules.
@Test
public void getSizeTotal_withSelectModules() throws Exception {
Variant lVariant = createVariant(lPlusVariantTargeting(), createSplitApkSet(/* moduleName= */
"base", createMasterApkDescription(ApkTargeting.getDefaultInstance(), ZipPath.create("base-master.apk"))), createSplitApkSet(/* moduleName= */
"feature1", DeliveryType.ON_DEMAND, /* moduleDependencies= */
ImmutableList.of(), createMasterApkDescription(ApkTargeting.getDefaultInstance(), ZipPath.create("base-feature1.apk"))), createSplitApkSet(/* moduleName= */
"feature2", DeliveryType.ON_DEMAND, /* moduleDependencies= */
ImmutableList.of("feature3"), createMasterApkDescription(ApkTargeting.getDefaultInstance(), ZipPath.create("base-feature2.apk"))), createSplitApkSet(/* moduleName= */
"feature3", DeliveryType.ON_DEMAND, /* moduleDependencies= */
ImmutableList.of(), createMasterApkDescription(ApkTargeting.getDefaultInstance(), ZipPath.create("base-feature3.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).setModules(ImmutableSet.of("base", "feature2")).build().getSizeTotal(new PrintStream(outputStream));
// base, feature2, feature 3 modules are selected and standalone variants are skipped.
assertThat(new String(outputStream.toByteArray(), UTF_8)).isEqualTo("MIN,MAX" + CRLF + String.format("%d,%d", 3 * compressedApkSize, 3 * compressedApkSize) + CRLF);
}
use of com.android.bundle.Commands.Variant in project bundletool by google.
the class VariantMatcherTest method getAllMatchingVariants_apexVariants_noMatch_throws.
@Test
public void getAllMatchingVariants_apexVariants_noMatch_throws() {
ZipPath x86Apk = ZipPath.create("standalone-x86.apk");
ZipPath x64X86Apk = ZipPath.create("standalone-x86_64.x86.apk");
ImmutableSet<ImmutableSet<AbiAlias>> x86Set = ImmutableSet.of(ImmutableSet.of(X86));
ImmutableSet<ImmutableSet<AbiAlias>> x64X86Set = ImmutableSet.of(ImmutableSet.of(X86_64, X86));
MultiAbiTargeting x86Targeting = multiAbiTargeting(x86Set, x64X86Set);
MultiAbiTargeting x64X86Targeting = multiAbiTargeting(x64X86Set, x86Set);
Variant x86Variant = multiAbiTargetingApexVariant(x86Targeting, x86Apk);
Variant x64X86Variant = multiAbiTargetingApexVariant(x64X86Targeting, x64X86Apk);
BuildApksResult buildApksResult = BuildApksResult.newBuilder().addAllVariant(ImmutableList.of(x86Variant, x64X86Variant)).build();
IncompatibleDeviceException e = assertThrows(IncompatibleDeviceException.class, () -> new VariantMatcher(abis("x86_64", "armeabi-v7a")).getAllMatchingVariants(buildApksResult));
assertThat(e).hasMessageThat().contains("No set of ABI architectures that the app supports is contained in the ABI " + "architecture set of the device");
}
Aggregations