use of com.android.bundle.Devices.DeviceSpec in project bundletool by google.
the class ExtractApksCommandTest method oneModule_extractedToTemporaryDirectory.
@Test
public void oneModule_extractedToTemporaryDirectory() 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 apksArchiveFile = createApksArchiveFile(tableOfContentsProto, tmpDir.resolve("bundle.apks"));
DeviceSpec deviceSpec = deviceWithSdk(21);
ExtractApksCommand command = ExtractApksCommand.builder().setApksArchivePath(apksArchiveFile).setDeviceSpec(deviceSpec).build();
ImmutableList<Path> matchedApks = command.execute();
assertThat(matchedApks).hasSize(1);
String apkOnePathPrefix = Paths.get(System.getProperty("java.io.tmpdir")).resolve("bundletool-extracted-apks").toString();
assertThat(Iterables.getOnlyElement(matchedApks).toString()).startsWith(apkOnePathPrefix);
}
use of com.android.bundle.Devices.DeviceSpec in project bundletool by google.
the class ExtractApksCommandTest method extractInstant_withNoInstantModules.
@Test
public void extractInstant_withNoInstantModules() 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(sdkVersionFrom(21), ImmutableSet.of(SdkVersion.getDefaultInstance())), createStandaloneApkSet(ApkTargeting.getDefaultInstance(), apkPreL))).addVariant(createVariant(variantSdkTargeting(sdkVersionFrom(21), ImmutableSet.of(SdkVersion.getDefaultInstance())), createSplitApkSet("base", createMasterApkDescription(ApkTargeting.getDefaultInstance(), apkLBase)), createSplitApkSet("feature", createMasterApkDescription(ApkTargeting.getDefaultInstance(), apkLFeature)), createSplitApkSet("other", createMasterApkDescription(ApkTargeting.getDefaultInstance(), apkLOther)))).build();
Path apksArchiveFile = createApksArchiveFile(tableOfContentsProto, tmpDir.resolve("bundle.apks"));
DeviceSpec deviceSpec = deviceWithSdk(21);
IncompatibleDeviceException exception = assertThrows(IncompatibleDeviceException.class, () -> ExtractApksCommand.builder().setApksArchivePath(apksArchiveFile).setDeviceSpec(deviceSpec).setInstant(true).build().execute());
assertThat(exception).hasMessageThat().contains("No compatible APKs found for the device");
}
use of com.android.bundle.Devices.DeviceSpec in project bundletool by google.
the class ExtractApksCommandTest method conditionalModule_deviceNotMatching_moduleInFlags.
@Test
public void conditionalModule_deviceNotMatching_moduleInFlags() throws Exception {
ZipPath apkBase = ZipPath.create("apkL-base.apk");
ZipPath apkConditional = ZipPath.create("apkN-conditional-module.apk");
BuildApksResult tableOfContentsProto = BuildApksResult.newBuilder().setBundletool(Bundletool.newBuilder().setVersion(BundleToolVersion.getCurrentVersion().toString())).addVariant(createVariant(variantSdkTargeting(sdkVersionFrom(21), ImmutableSet.of(sdkVersionFrom(1))), createSplitApkSet("base", createMasterApkDescription(ApkTargeting.getDefaultInstance(), apkBase)), createConditionalApkSet("conditional", mergeModuleTargeting(moduleMinSdkVersionTargeting(24), moduleFeatureTargeting("android.hardware.camera.ar")), createMasterApkDescription(ApkTargeting.getDefaultInstance(), apkConditional)))).build();
Path apksArchiveFile = createApksArchiveFile(tableOfContentsProto, tmpDir.resolve("bundle.apks"));
DeviceSpec deviceSpec = mergeSpecs(deviceWithSdk(21));
ImmutableList<Path> matchedApks = ExtractApksCommand.builder().setApksArchivePath(apksArchiveFile).setDeviceSpec(deviceSpec).setOutputDirectory(tmpDir).setModules(ImmutableSet.of("conditional")).build().execute();
assertThat(matchedApks).containsExactly(inOutputDirectory(apkConditional), 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_Mdevice_matchesMSplit.
@Test
@Theory
public void oneModule_Mdevice_matchesMSplit(@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(23);
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(apkM.toString()));
} else {
assertThat(matchedApks).containsExactly(inOutputDirectory(apkM.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 outputDirectoryCreatedIfDoesNotExist.
@Test
public void outputDirectoryCreatedIfDoesNotExist() throws Exception {
Path apksArchivePath = createApksArchiveFile(minimalApkSet(), tmpDir.resolve("bundle.apks"));
DeviceSpec deviceSpec = deviceWithSdk(21);
Path outputDirectory = tmpDir.resolve("directory-that-does-not-exist");
ExtractApksCommand.builder().setApksArchivePath(apksArchivePath).setDeviceSpec(deviceSpec).setOutputDirectory(outputDirectory).build().execute();
assertThat(Files.exists(outputDirectory)).isTrue();
}
Aggregations