use of com.android.tools.build.bundletool.model.ZipPath 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.tools.build.bundletool.model.ZipPath 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.tools.build.bundletool.model.ZipPath 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.tools.build.bundletool.model.ZipPath 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.tools.build.bundletool.model.ZipPath 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");
}
Aggregations