use of com.android.bundle.Commands.ExtractApksResult in project bundletool by google.
the class ExtractApksCommandTest method extractApks_producesOutputMetadata.
@Test
@Theory
public void extractApks_producesOutputMetadata(@FromDataPoints("localTestingEnabled") boolean localTestingEnabled) throws Exception {
String onDemandModule = "ondemand_assetmodule";
ZipPath apkBase = ZipPath.create("base-master.apk");
ZipPath apkFeature1 = ZipPath.create("feature1-master.apk");
ZipPath apkFeature2 = ZipPath.create("feature2-master.apk");
ZipPath onDemandMasterApk = ZipPath.create(onDemandModule + "-master.apk");
BuildApksResult tableOfContentsProto = BuildApksResult.newBuilder().setBundletool(Bundletool.newBuilder().setVersion(BundleToolVersion.getCurrentVersion().toString())).addVariant(createVariant(variantSdkTargeting(sdkVersionFrom(21), ImmutableSet.of(SdkVersion.getDefaultInstance())), createSplitApkSet(/* moduleName= */
"base", createMasterApkDescription(ApkTargeting.getDefaultInstance(), apkBase)), createSplitApkSet(/* moduleName= */
"feature1", DeliveryType.ON_DEMAND, /* moduleDependencies= */
ImmutableList.of(), createMasterApkDescription(ApkTargeting.getDefaultInstance(), apkFeature1)), createSplitApkSet(/* moduleName= */
"feature2", DeliveryType.ON_DEMAND, /* moduleDependencies= */
ImmutableList.of("feature1"), createMasterApkDescription(ApkTargeting.getDefaultInstance(), apkFeature2)))).addAssetSliceSet(AssetSliceSet.newBuilder().setAssetModuleMetadata(AssetModuleMetadata.newBuilder().setName(onDemandModule).setDeliveryType(DeliveryType.ON_DEMAND)).addApkDescription(splitApkDescription(ApkTargeting.getDefaultInstance(), onDemandMasterApk))).build();
if (localTestingEnabled) {
tableOfContentsProto = tableOfContentsProto.toBuilder().setPackageName("com.acme.anvil").setLocalTestingInfo(LocalTestingInfo.newBuilder().setEnabled(true).setLocalTestingPath("local_testing_dir")).build();
}
Path apksArchiveFile = createApksArchiveFile(tableOfContentsProto, tmpDir.resolve("bundle.apks"));
DeviceSpec deviceSpec = deviceWithSdk(21);
ImmutableList<Path> apks = ExtractApksCommand.builder().setApksArchivePath(apksArchiveFile).setDeviceSpec(deviceSpec).setOutputDirectory(tmpDir).setModules(ImmutableSet.of("feature2", "ondemand_assetmodule")).setIncludeMetadata(true).build().execute();
assertThat(apks).containsExactly(inOutputDirectory(apkBase), inOutputDirectory(apkFeature1), inOutputDirectory(apkFeature2), inOutputDirectory(onDemandMasterApk));
Path metadataFile = inTempDirectory("metadata.json");
assertThat(Files.isRegularFile(metadataFile)).isTrue();
ExtractApksResult expectedResult = ExtractApksResult.newBuilder().addApks(ExtractedApk.newBuilder().setPath(apkBase.toString()).setDeliveryType(DeliveryType.INSTALL_TIME).setModuleName("base").build()).addApks(ExtractedApk.newBuilder().setPath(apkFeature1.toString()).setDeliveryType(DeliveryType.ON_DEMAND).setModuleName("feature1").build()).addApks(ExtractedApk.newBuilder().setPath(apkFeature2.toString()).setDeliveryType(DeliveryType.ON_DEMAND).setModuleName("feature2").build()).addApks(ExtractedApk.newBuilder().setPath(onDemandMasterApk.toString()).setDeliveryType(DeliveryType.ON_DEMAND).setModuleName("ondemand_assetmodule").build()).build();
if (localTestingEnabled) {
expectedResult = expectedResult.toBuilder().setLocalTestingInfo(LocalTestingInfoForMetadata.newBuilder().setLocalTestingDir("/sdcard/Android/data/com.acme.anvil/files/local_testing_dir")).build();
}
assertThat(parseExtractApksResult(metadataFile)).ignoringRepeatedFieldOrder().isEqualTo(expectedResult);
}
Aggregations