use of com.android.bundle.Devices.DeviceSpec in project bundletool by google.
the class ExtractApksCommandTest method extractInstant_withBaseOnly.
@Test
public void extractInstant_withBaseOnly() throws Exception {
ZipPath apkLBase = ZipPath.create("apkL-base.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(), apkLBase))).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(apkLBase));
for (Path matchedApk : matchedApks) {
checkFileExistsAndReadable(tmpDir.resolve(matchedApk));
}
}
use of com.android.bundle.Devices.DeviceSpec in project bundletool by google.
the class ExtractApksCommandTest method twoModules_Ldevice_matchesLSplitsForSpecifiedModules.
@Test
public void twoModules_Ldevice_matchesLSplitsForSpecifiedModules() throws Exception {
ZipPath apkPreL = ZipPath.create("apkPreL.apk");
ZipPath apkLBase = ZipPath.create("apkL-base.apk");
ZipPath apkLFeature = ZipPath.create("apkL-feature.apk");
ZipPath apkLOther = ZipPath.create("apkL-other.apk");
BuildApksResult tableOfContentsProto = BuildApksResult.newBuilder().setBundletool(Bundletool.newBuilder().setVersion(BundleToolVersion.getCurrentVersion().toString())).addVariant(createVariant(variantSdkTargeting(SdkVersion.getDefaultInstance(), ImmutableSet.of(sdkVersionFrom(21))), createStandaloneApkSet(ApkTargeting.getDefaultInstance(), apkPreL))).addVariant(createVariant(variantSdkTargeting(sdkVersionFrom(21), ImmutableSet.of(SdkVersion.getDefaultInstance())), createSplitApkSet("base", createMasterApkDescription(ApkTargeting.getDefaultInstance(), apkLBase)), createSplitApkSet("feature", DeliveryType.ON_DEMAND, /* moduleDependencies= */
ImmutableList.of(), createMasterApkDescription(ApkTargeting.getDefaultInstance(), apkLFeature)), createSplitApkSet("other", DeliveryType.ON_DEMAND, /* moduleDependencies= */
ImmutableList.of(), createMasterApkDescription(ApkTargeting.getDefaultInstance(), apkLOther)))).build();
Path apksArchiveFile = createApksArchiveFile(tableOfContentsProto, tmpDir.resolve("bundle.apks"));
DeviceSpec deviceSpec = deviceWithSdk(21);
ImmutableList<Path> matchedApks = ExtractApksCommand.builder().setApksArchivePath(apksArchiveFile).setDeviceSpec(deviceSpec).setOutputDirectory(tmpDir).setModules(ImmutableSet.of("feature")).build().execute();
assertThat(matchedApks).containsExactly(inOutputDirectory(apkLBase), inOutputDirectory(apkLFeature));
for (Path matchedApk : matchedApks) {
checkFileExistsAndReadable(tmpDir.resolve(matchedApk));
}
}
use of com.android.bundle.Devices.DeviceSpec in project bundletool by google.
the class ExtractApksCommandTest method extractInstant_withMultipleInstantModule.
@Test
public void extractInstant_withMultipleInstantModule() throws Exception {
ZipPath apkBase = ZipPath.create("apkL-base.apk");
ZipPath apkInstant = ZipPath.create("apkL-instant.apk");
ZipPath apkInstant2 = ZipPath.create("apkL-instant2.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), createInstantApkSet("other", ApkTargeting.getDefaultInstance(), apkInstant2))).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(apkInstant2), 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_matchesLSplit.
@Test
@Theory
public void oneModule_Ldevice_matchesLSplit(@FromDataPoints("apksInDirectory") boolean apksInDirectory) throws Exception {
ZipPath apkPreL = ZipPath.create("standalones/apkPreL.apk");
ZipPath apkL = ZipPath.create("splits/apkL.apk");
ZipPath apkM = ZipPath.create("splits/apkM.apk");
BuildApksResult tableOfContentsProto = BuildApksResult.newBuilder().setBundletool(Bundletool.newBuilder().setVersion(BundleToolVersion.getCurrentVersion().toString())).addVariant(createVariantForSingleSplitApk(variantSdkTargeting(SdkVersion.getDefaultInstance(), ImmutableSet.of(sdkVersionFrom(21), sdkVersionFrom(23))), ApkTargeting.getDefaultInstance(), apkPreL)).addVariant(createVariantForSingleSplitApk(variantSdkTargeting(sdkVersionFrom(21), ImmutableSet.of(SdkVersion.getDefaultInstance(), sdkVersionFrom(23))), ApkTargeting.getDefaultInstance(), apkL)).addVariant(createVariantForSingleSplitApk(variantSdkTargeting(sdkVersionFrom(23), ImmutableSet.of(SdkVersion.getDefaultInstance(), sdkVersionFrom(21))), ApkTargeting.getDefaultInstance(), apkM)).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(apkL.toString()));
} else {
assertThat(matchedApks).containsExactly(inOutputDirectory(apkL.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 builderAndFlagsConstruction_optionalOutputDirectory_equivalent.
@Test
public void builderAndFlagsConstruction_optionalOutputDirectory_equivalent() throws Exception {
DeviceSpec deviceSpec = deviceWithSdk(21);
Path deviceSpecFile = createDeviceSpecFile(deviceSpec, tmpDir.resolve("device.json"));
BuildApksResult tableOfContentsProto = minimalApkSet();
Path apksArchiveFile = createApksArchiveFile(tableOfContentsProto, tmpDir.resolve("bundle.apks"));
ExtractApksCommand fromFlags = ExtractApksCommand.fromFlags(new FlagParser().parse("--device-spec=" + deviceSpecFile, "--apks=" + apksArchiveFile, // Optional values.
"--output-dir=" + tmp.getRoot()));
ExtractApksCommand fromBuilderApi = ExtractApksCommand.builder().setApksArchivePath(apksArchiveFile).setDeviceSpec(deviceSpec).setOutputDirectory(tmpDir).build();
assertThat(fromFlags).isEqualTo(fromBuilderApi);
}
Aggregations