use of com.android.bundle.Devices.DeviceSpec in project bundletool by google.
the class ExtractApksCommandTest method deviceSpecFromPbJson.
@Test
public void deviceSpecFromPbJson() throws Exception {
DeviceSpec.Builder expectedDeviceSpecBuilder = DeviceSpec.newBuilder();
try (Reader reader = TestData.openReader("testdata/device/pixel2_spec.json")) {
JsonFormat.parser().merge(reader, expectedDeviceSpecBuilder);
}
DeviceSpec expectedDeviceSpec = expectedDeviceSpecBuilder.build();
BuildApksResult tableOfContentsProto = minimalApkSet();
Path apksArchiveFile = createApksArchiveFile(tableOfContentsProto, tmpDir.resolve("bundle.apks"));
Path deviceSpecFile = copyToTempDir("testdata/device/pixel2_spec.json");
ExtractApksCommand command = ExtractApksCommand.fromFlags(new FlagParser().parse("--device-spec=" + deviceSpecFile, "--apks=" + apksArchiveFile));
assertThat(command.getDeviceSpec()).isEqualTo(expectedDeviceSpec);
}
use of com.android.bundle.Devices.DeviceSpec in project bundletool by google.
the class ExtractApksCommandTest method extractInstant_withBaseAndSingleInstantModule.
@Test
public void extractInstant_withBaseAndSingleInstantModule() throws Exception {
ZipPath apkBase = ZipPath.create("apkL-base.apk");
ZipPath apkInstant = ZipPath.create("apkL-instant.apk");
ZipPath apkOther = ZipPath.create("apkL-other.apk");
BuildApksResult tableOfContentsProto = BuildApksResult.newBuilder().setBundletool(Bundletool.newBuilder().setVersion(BundleToolVersion.getCurrentVersion().toString())).addVariant(createVariant(variantSdkTargeting(sdkVersionFrom(21), ImmutableSet.of(SdkVersion.getDefaultInstance())), createInstantApkSet("base", ApkTargeting.getDefaultInstance(), apkBase), createInstantApkSet("instant", ApkTargeting.getDefaultInstance(), apkInstant))).addVariant(createVariant(variantSdkTargeting(sdkVersionFrom(21), ImmutableSet.of(SdkVersion.getDefaultInstance())), createSplitApkSet("other", createMasterApkDescription(ApkTargeting.getDefaultInstance(), apkOther)))).build();
Path apksArchiveFile = createApksArchiveFile(tableOfContentsProto, tmpDir.resolve("bundle.apks"));
DeviceSpec deviceSpec = deviceWithSdk(21);
ImmutableList<Path> matchedApks = ExtractApksCommand.builder().setApksArchivePath(apksArchiveFile).setDeviceSpec(deviceSpec).setOutputDirectory(tmpDir).setInstant(true).build().execute();
assertThat(matchedApks).containsExactly(inOutputDirectory(apkInstant), inOutputDirectory(apkBase));
for (Path matchedApk : matchedApks) {
checkFileExistsAndReadable(tmpDir.resolve(matchedApk));
}
}
use of com.android.bundle.Devices.DeviceSpec in project bundletool by google.
the class ExtractApksCommandTest method oneModule_Ldevice_matchesLmasterSplit.
@Test
@Theory
public void oneModule_Ldevice_matchesLmasterSplit(@FromDataPoints("apksInDirectory") boolean apksInDirectory) throws Exception {
ZipPath apkOne = ZipPath.create("apk_one.apk");
BuildApksResult tableOfContentsProto = BuildApksResult.newBuilder().setBundletool(Bundletool.newBuilder().setVersion(BundleToolVersion.getCurrentVersion().toString())).addVariant(createVariantForSingleSplitApk(variantSdkTargeting(sdkVersionFrom(21)), ApkTargeting.getDefaultInstance(), apkOne)).build();
Path apksPath = createApks(tableOfContentsProto, apksInDirectory);
DeviceSpec deviceSpec = deviceWithSdk(21);
ExtractApksCommand.Builder extractedApksCommand = ExtractApksCommand.builder().setApksArchivePath(apksPath).setDeviceSpec(deviceSpec);
if (!apksInDirectory) {
extractedApksCommand.setOutputDirectory(tmpDir);
}
ImmutableList<Path> matchedApks = extractedApksCommand.build().execute();
if (apksInDirectory) {
assertThat(matchedApks).containsExactly(inTempDirectory(apkOne.toString()));
} else {
assertThat(matchedApks).containsExactly(inOutputDirectory(apkOne.getFileName()));
}
for (Path matchedApk : matchedApks) {
checkFileExistsAndReadable(tmpDir.resolve(matchedApk));
}
}
use of com.android.bundle.Devices.DeviceSpec 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);
}
use of com.android.bundle.Devices.DeviceSpec in project bundletool by google.
the class ApkMatcherTest method apkMatch_withModuleNameFiltering_splitApks_permanentlyMergedModule.
@Test
public void apkMatch_withModuleNameFiltering_splitApks_permanentlyMergedModule() {
DeviceSpec device = deviceWithSdk(21);
ZipPath apk = ZipPath.create("master-de-fr.apk");
BuildApksResult buildApksResult = buildApksResult(createVariant(VariantTargeting.getDefaultInstance(), splitApkSet(/* moduleName= */
"base", splitApkDescription(ApkTargeting.getDefaultInstance(), apk)))).toBuilder().addPermanentlyFusedModules(PermanentlyFusedModule.newBuilder().setName("my-module")).build();
ImmutableList<GeneratedApk> matchedApks = createMatcher(device, Optional.of(ImmutableSet.of("my-module"))).getMatchingApks(buildApksResult);
assertThat(matchedApks).containsExactly(baseMatchedApk(apk));
}
Aggregations