use of com.android.bundle.Devices.DeviceSpec in project bundletool by google.
the class ExtractApksCommandTest method conditionalModule_deviceMatching.
@Test
public void conditionalModule_deviceMatching() 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(24), deviceFeatures("android.hardware.camera.ar"));
ImmutableList<Path> matchedApks = ExtractApksCommand.builder().setApksArchivePath(apksArchiveFile).setDeviceSpec(deviceSpec).setOutputDirectory(tmpDir).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 bundleWithDeviceTierTargeting_noDeviceTierSpecified_usesDefaults.
@Test
public void bundleWithDeviceTierTargeting_noDeviceTierSpecified_usesDefaults() throws Exception {
ZipPath baseMasterApk = ZipPath.create("base-master.apk");
ZipPath baseLowApk = ZipPath.create("base-tier_0.apk");
ZipPath baseHighApk = ZipPath.create("base-tier_1.apk");
BuildApksResult buildApksResult = BuildApksResult.newBuilder().setBundletool(Bundletool.newBuilder().setVersion(BundleToolVersion.getCurrentVersion().toString())).addVariant(createVariant(variantSdkTargeting(sdkVersionFrom(21), ImmutableSet.of(SdkVersion.getDefaultInstance())), createSplitApkSet("base", createMasterApkDescription(ApkTargeting.getDefaultInstance(), baseMasterApk), splitApkDescription(apkDeviceTierTargeting(deviceTierTargeting(/* value= */
0, /* alternatives= */
ImmutableList.of(1))), baseLowApk), splitApkDescription(apkDeviceTierTargeting(deviceTierTargeting(/* value= */
1, /* alternatives= */
ImmutableList.of(0))), baseHighApk)))).addDefaultTargetingValue(DefaultTargetingValue.newBuilder().setDimension(Value.DEVICE_TIER).setDefaultValue("1")).build();
Path apksArchiveFile = createApksArchiveFile(buildApksResult, tmpDir.resolve("bundle.apks"));
DeviceSpec deviceSpec = lDevice();
ImmutableList<Path> matchedApks = ExtractApksCommand.builder().setApksArchivePath(apksArchiveFile).setDeviceSpec(deviceSpec).setOutputDirectory(tmpDir).build().execute();
// Master and high tier splits for base and asset module.
assertThat(matchedApks).containsExactly(inOutputDirectory(baseMasterApk), inOutputDirectory(baseHighApk));
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_MipsDevice_noMatchingAbiSplit_throws.
@Test
public void oneModule_MipsDevice_noMatchingAbiSplit_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(AbiAlias.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));
ExtractApksCommand command = ExtractApksCommand.builder().setApksArchivePath(apksArchiveFile).setDeviceSpec(deviceSpec).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]");
}
use of com.android.bundle.Devices.DeviceSpec in project bundletool by google.
the class ExtractApksCommandTest method shortcutToExtractAllModules.
/**
* Ensures that --modules=_ALL_ extracts all modules.
*/
@Test
public void shortcutToExtractAllModules() throws Exception {
ZipPath apkBase = ZipPath.create("base-master.apk");
ZipPath apkBaseXxhdpi = ZipPath.create("base-xxhdpi.apk");
ZipPath apkFeature = ZipPath.create("feature-master.apk");
ZipPath apkFeatureXxhdpi = ZipPath.create("feature-xxhdpi.apk");
ZipPath apkFeature2 = ZipPath.create("feature2.apk");
ZipPath apkFeature2Arm64 = ZipPath.create("feature2-arm64_v8a.apk");
BuildApksResult tableOfContentsProto = BuildApksResult.newBuilder().setBundletool(Bundletool.newBuilder().setVersion(BundleToolVersion.getCurrentVersion().toString())).addVariant(createVariant(variantSdkTargeting(sdkVersionFrom(21), ImmutableSet.of(SdkVersion.getDefaultInstance())), createSplitApkSet("base", createMasterApkDescription(ApkTargeting.getDefaultInstance(), apkBase), createApkDescription(apkDensityTargeting(XXHDPI), apkBaseXxhdpi, false)), createSplitApkSet("feature", DeliveryType.ON_DEMAND, /* moduleDependencies= */
ImmutableList.of("feature2"), createMasterApkDescription(ApkTargeting.getDefaultInstance(), apkFeature), createApkDescription(apkDensityTargeting(XXHDPI), apkFeatureXxhdpi, false)), createSplitApkSet("feature2", DeliveryType.ON_DEMAND, /* moduleDependencies= */
ImmutableList.of(), createMasterApkDescription(ApkTargeting.getDefaultInstance(), apkFeature2), createApkDescription(apkAbiTargeting(ARM64_V8A), apkFeature2Arm64, false)))).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("_ALL_")).build().execute();
assertThat(matchedApks).containsExactly(inOutputDirectory(apkBase), inOutputDirectory(apkBaseXxhdpi), inOutputDirectory(apkFeature), inOutputDirectory(apkFeatureXxhdpi), inOutputDirectory(apkFeature2), inOutputDirectory(apkFeature2Arm64));
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_optionalInstantFalse_equivalent.
@Test
public void builderAndFlagsConstruction_optionalInstantFalse_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));
ExtractApksCommand fromBuilderApi = ExtractApksCommand.builder().setApksArchivePath(apksArchiveFile).setDeviceSpec(deviceSpec).setInstant(false).build();
assertThat(fromFlags).isEqualTo(fromBuilderApi);
}
Aggregations