use of com.android.bundle.Commands.BuildApksResult 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.BuildApksResult in project bundletool by google.
the class InstallApksCommandTest method localTestingMode_allModules.
@Test
@Theory
public void localTestingMode_allModules(@FromDataPoints("apksInDirectory") boolean apksInDirectory) throws Exception {
String installTimeFeature = "installtime_feature";
String onDemandFeature = "ondemand_feature";
String installTimeAsset = "installtime_asset";
String onDemandAsset = "ondemand_asset";
ZipPath baseApk = ZipPath.create("base-master.apk");
ZipPath baseEnApk = ZipPath.create("base-en.apk");
ZipPath installTimeFeatureMasterApk = ZipPath.create(installTimeFeature + "-master.apk");
ZipPath installTimeFeatureEnApk = ZipPath.create(installTimeFeature + "-en.apk");
ZipPath installTimeFeaturePlApk = ZipPath.create(installTimeFeature + "-pl.apk");
ZipPath onDemandFeatureMasterApk = ZipPath.create(onDemandFeature + "-master.apk");
ZipPath installTimeAssetMasterApk = ZipPath.create(installTimeAsset + "-master.apk");
ZipPath installTimeAssetEnApk = ZipPath.create(installTimeAsset + "-en.apk");
ZipPath onDemandAssetMasterApk = ZipPath.create(onDemandAsset + "-master.apk");
BuildApksResult tableOfContent = BuildApksResult.newBuilder().setPackageName(PKG_NAME).setBundletool(Bundletool.newBuilder().setVersion(BundleToolVersion.getCurrentVersion().toString())).addVariant(createVariant(VariantTargeting.getDefaultInstance(), createSplitApkSet("base", createMasterApkDescription(ApkTargeting.getDefaultInstance(), baseApk), createApkDescription(apkLanguageTargeting("en"), baseEnApk, /* isMasterSplit= */
false)), createSplitApkSet(installTimeFeature, createMasterApkDescription(ApkTargeting.getDefaultInstance(), installTimeFeatureMasterApk), createApkDescription(apkLanguageTargeting("en"), installTimeFeatureEnApk, /* isMasterSplit= */
false), createApkDescription(apkLanguageTargeting("pl"), installTimeFeaturePlApk, /* isMasterSplit= */
false)), createSplitApkSet(onDemandFeature, DeliveryType.ON_DEMAND, /* moduleDependencies= */
ImmutableList.of(), createMasterApkDescription(ApkTargeting.getDefaultInstance(), onDemandFeatureMasterApk)))).addAssetSliceSet(AssetSliceSet.newBuilder().setAssetModuleMetadata(AssetModuleMetadata.newBuilder().setName(installTimeAsset).setDeliveryType(DeliveryType.INSTALL_TIME)).addApkDescription(splitApkDescription(ApkTargeting.getDefaultInstance(), installTimeAssetMasterApk)).addApkDescription(splitApkDescription(apkLanguageTargeting("en"), installTimeAssetEnApk))).addAssetSliceSet(AssetSliceSet.newBuilder().setAssetModuleMetadata(AssetModuleMetadata.newBuilder().setName(onDemandAsset).setDeliveryType(DeliveryType.ON_DEMAND)).addApkDescription(splitApkDescription(ApkTargeting.getDefaultInstance(), onDemandAssetMasterApk))).setLocalTestingInfo(LocalTestingInfo.newBuilder().setEnabled(true).setLocalTestingPath("local_testing").build()).build();
Path apksFile = createApks(tableOfContent, apksInDirectory);
List<Path> installedApks = new ArrayList<>();
List<Path> pushedFiles = new ArrayList<>();
FakeDevice fakeDevice = FakeDevice.fromDeviceSpec(DEVICE_ID, DeviceState.ONLINE, lDeviceWithLocales("en-US"));
AdbServer adbServer = new FakeAdbServer(/* hasInitialDeviceList= */
true, ImmutableList.of(fakeDevice));
fakeDevice.setInstallApksSideEffect((apks, installOptions) -> installedApks.addAll(apks));
fakeDevice.setPushSideEffect((files, installOptions) -> pushedFiles.addAll(files));
InstallApksCommand.builder().setApksArchivePath(apksFile).setAdbPath(adbPath).setAdbServer(adbServer).setModules(ImmutableSet.of("_ALL_")).build().execute();
// Base, install-time and on-demand features and install-time assets.
assertThat(getFileNames(installedApks)).containsExactly(baseApk.toString(), baseEnApk.toString(), installTimeFeatureMasterApk.toString(), installTimeFeatureEnApk.toString(), onDemandFeatureMasterApk.toString(), installTimeAssetMasterApk.toString(), installTimeAssetEnApk.toString());
// Base config splits, install-time and on-demand features and on-demand assets. All languages.
assertThat(getFileNames(pushedFiles)).containsExactly(baseEnApk.toString(), installTimeFeatureMasterApk.toString(), installTimeFeatureEnApk.toString(), installTimeFeaturePlApk.toString(), onDemandFeatureMasterApk.toString(), onDemandAssetMasterApk.toString());
}
use of com.android.bundle.Commands.BuildApksResult in project bundletool by google.
the class InstallApksCommandTest method localTestingMode_defaultModules.
@Test
@Theory
public void localTestingMode_defaultModules(@FromDataPoints("apksInDirectory") boolean apksInDirectory) throws Exception {
String installTimeFeature = "installtime_feature";
String onDemandFeature = "ondemand_feature";
String installTimeAsset = "installtime_asset";
String onDemandAsset = "ondemand_asset";
ZipPath baseApk = ZipPath.create("base-master.apk");
ZipPath baseEnApk = ZipPath.create("base-en.apk");
ZipPath installTimeFeatureMasterApk = ZipPath.create(installTimeFeature + "-master.apk");
ZipPath installTimeFeatureEnApk = ZipPath.create(installTimeFeature + "-en.apk");
ZipPath installTimeFeaturePlApk = ZipPath.create(installTimeFeature + "-pl.apk");
ZipPath onDemandFeatureMasterApk = ZipPath.create(onDemandFeature + "-master.apk");
ZipPath installTimeAssetMasterApk = ZipPath.create(installTimeAsset + "-master.apk");
ZipPath installTimeAssetEnApk = ZipPath.create(installTimeAsset + "-en.apk");
ZipPath onDemandAssetMasterApk = ZipPath.create(onDemandAsset + "-master.apk");
BuildApksResult tableOfContent = BuildApksResult.newBuilder().setPackageName(PKG_NAME).setBundletool(Bundletool.newBuilder().setVersion(BundleToolVersion.getCurrentVersion().toString())).addVariant(createVariant(VariantTargeting.getDefaultInstance(), createSplitApkSet("base", createMasterApkDescription(ApkTargeting.getDefaultInstance(), baseApk), createApkDescription(apkLanguageTargeting("en"), baseEnApk, /* isMasterSplit= */
false)), createSplitApkSet(installTimeFeature, createMasterApkDescription(ApkTargeting.getDefaultInstance(), installTimeFeatureMasterApk), createApkDescription(apkLanguageTargeting("en"), installTimeFeatureEnApk, /* isMasterSplit= */
false), createApkDescription(apkLanguageTargeting("pl"), installTimeFeaturePlApk, /* isMasterSplit= */
false)), createSplitApkSet(onDemandFeature, DeliveryType.ON_DEMAND, /* moduleDependencies= */
ImmutableList.of(), createMasterApkDescription(ApkTargeting.getDefaultInstance(), onDemandFeatureMasterApk)))).addAssetSliceSet(AssetSliceSet.newBuilder().setAssetModuleMetadata(AssetModuleMetadata.newBuilder().setName(installTimeAsset).setDeliveryType(DeliveryType.INSTALL_TIME)).addApkDescription(splitApkDescription(ApkTargeting.getDefaultInstance(), installTimeAssetMasterApk)).addApkDescription(splitApkDescription(apkLanguageTargeting("en"), installTimeAssetEnApk))).addAssetSliceSet(AssetSliceSet.newBuilder().setAssetModuleMetadata(AssetModuleMetadata.newBuilder().setName(onDemandAsset).setDeliveryType(DeliveryType.ON_DEMAND)).addApkDescription(splitApkDescription(ApkTargeting.getDefaultInstance(), onDemandAssetMasterApk))).setLocalTestingInfo(LocalTestingInfo.newBuilder().setEnabled(true).setLocalTestingPath("local_testing").build()).build();
Path apksFile = createApks(tableOfContent, apksInDirectory);
Duration timeout = Duration.ofMinutes(5);
List<Path> installedApks = new ArrayList<>();
List<Path> pushedFiles = new ArrayList<>();
List<String> clearedPathes = new ArrayList<>();
FakeDevice fakeDevice = FakeDevice.fromDeviceSpec(DEVICE_ID, DeviceState.ONLINE, lDeviceWithLocales("en-US"));
AdbServer adbServer = new FakeAdbServer(/* hasInitialDeviceList= */
true, ImmutableList.of(fakeDevice));
fakeDevice.setInstallApksSideEffect((apks, installOptions) -> {
assertThat(installOptions.getTimeout()).isEqualTo(timeout);
installedApks.addAll(apks);
});
fakeDevice.setPushSideEffect((files, pushOptions) -> {
assertThat(pushOptions.getTimeout()).isEqualTo(timeout);
pushedFiles.addAll(files);
});
fakeDevice.setRemoveRemotePathSideEffect((remotePath, runAs, removeTimeout) -> {
assertThat(removeTimeout).isEqualTo(timeout);
assertThat(runAs).hasValue(PKG_NAME);
clearedPathes.add(remotePath);
});
InstallApksCommand.builder().setApksArchivePath(apksFile).setAdbPath(adbPath).setAdbServer(adbServer).setTimeout(timeout).build().execute();
// Base, install-time features and install-time assets.
assertThat(getFileNames(installedApks)).containsExactly(baseApk.toString(), baseEnApk.toString(), installTimeFeatureMasterApk.toString(), installTimeFeatureEnApk.toString(), installTimeAssetMasterApk.toString(), installTimeAssetEnApk.toString());
// Base config splits, install-time and on-demand features and on-demand assets. All languages.
assertThat(getFileNames(pushedFiles)).containsExactly(baseEnApk.toString(), installTimeFeatureMasterApk.toString(), installTimeFeatureEnApk.toString(), installTimeFeaturePlApk.toString(), onDemandFeatureMasterApk.toString(), onDemandAssetMasterApk.toString());
assertThat(clearedPathes).containsExactly(LocalTestingPathResolver.getLocalTestingWorkingDir(PKG_NAME));
}
use of com.android.bundle.Commands.BuildApksResult in project bundletool by google.
the class InstallApksCommandTest method moduleDependencies_installDependency.
@Test
@Theory
public void moduleDependencies_installDependency(@FromDataPoints("apksInDirectory") boolean apksInDirectory) throws Exception {
BuildApksResult tableOfContent = BuildApksResult.newBuilder().setBundletool(Bundletool.newBuilder().setVersion(BundleToolVersion.getCurrentVersion().toString())).addVariant(createVariant(VariantTargeting.getDefaultInstance(), 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("feature1-master.apk"))), createSplitApkSet(/* moduleName= */
"feature2", DeliveryType.ON_DEMAND, /* moduleDependencies= */
ImmutableList.of("feature1"), createMasterApkDescription(ApkTargeting.getDefaultInstance(), ZipPath.create("feature2-master.apk"))), createSplitApkSet(/* moduleName= */
"feature3", DeliveryType.ON_DEMAND, /* moduleDependencies= */
ImmutableList.of("feature2"), createMasterApkDescription(ApkTargeting.getDefaultInstance(), ZipPath.create("feature3-master.apk"))))).build();
Path apksFile = createApks(tableOfContent, apksInDirectory);
List<Path> installedApks = new ArrayList<>();
FakeDevice fakeDevice = FakeDevice.fromDeviceSpec(DEVICE_ID, DeviceState.ONLINE, lDeviceWithLocales("en-US"));
AdbServer adbServer = new FakeAdbServer(/* hasInitialDeviceList= */
true, ImmutableList.of(fakeDevice));
fakeDevice.setInstallApksSideEffect((apks, installOptions) -> installedApks.addAll(apks));
InstallApksCommand.builder().setApksArchivePath(apksFile).setAdbPath(adbPath).setAdbServer(adbServer).setModules(ImmutableSet.of("feature2")).build().execute();
assertThat(getFileNames(installedApks)).containsExactly("base-master.apk", "feature1-master.apk", "feature2-master.apk");
}
use of com.android.bundle.Commands.BuildApksResult in project bundletool by google.
the class InstallApksCommandTest method deviceAbiIncompatible_throws.
@Test
public void deviceAbiIncompatible_throws() throws Exception {
ZipPath apkL = ZipPath.create("splits/apkL.apk");
ZipPath apkLx86 = ZipPath.create("splits/apkL-x86.apk");
BuildApksResult tableOfContentsProto = BuildApksResult.newBuilder().setBundletool(Bundletool.newBuilder().setVersion(BundleToolVersion.getCurrentVersion().toString())).addVariant(createVariant(variantSdkTargeting(sdkVersionFrom(21)), createSplitApkSet("base", createMasterApkDescription(ApkTargeting.getDefaultInstance(), apkL), createApkDescription(apkAbiTargeting(X86, ImmutableSet.of()), apkLx86, /* isMasterSplit= */
false)))).build();
Path apksArchiveFile = createApksArchiveFile(tableOfContentsProto, tmpDir.resolve("bundle.apks"));
DeviceSpec deviceSpec = mergeSpecs(sdkVersion(21), abis("arm64-v8a"), locales("en-US"), density(DensityAlias.HDPI));
FakeDevice fakeDevice = FakeDevice.fromDeviceSpec(DEVICE_ID, DeviceState.ONLINE, deviceSpec);
AdbServer adbServer = new FakeAdbServer(/* hasInitialDeviceList= */
true, ImmutableList.of(fakeDevice));
InstallApksCommand command = InstallApksCommand.builder().setApksArchivePath(apksArchiveFile).setAdbPath(adbPath).setAdbServer(adbServer).build();
Throwable exception = assertThrows(IncompatibleDeviceException.class, command::execute);
assertThat(exception).hasMessageThat().contains("The app doesn't support ABI architectures of the device. Device ABIs: [arm64-v8a], " + "app ABIs: [x86]");
}
Aggregations