use of com.android.bundle.Devices.DeviceSpec in project bundletool by google.
the class GetSizeCommandTest method builderAndFlagsConstruction_optionalDeviceSpec_inJavaViaFiles_equivalent.
@Test
public void builderAndFlagsConstruction_optionalDeviceSpec_inJavaViaFiles_equivalent() throws Exception {
DeviceSpec deviceSpec = deviceWithSdk(21);
Path deviceSpecFile = createDeviceSpecFile(deviceSpec, tmpDir.resolve("device.json"));
BuildApksResult tableOfContentsProto = BuildApksResult.getDefaultInstance();
Path apksArchiveFile = createApksArchiveFile(tableOfContentsProto, tmpDir.resolve("bundle.apks"));
GetSizeCommand fromFlags = GetSizeCommand.fromFlags(new FlagParser().parse("get-size", "total", "--apks=" + apksArchiveFile, // Optional values.
"--device-spec=" + deviceSpecFile));
GetSizeCommand fromBuilderApi = GetSizeCommand.builder().setApksArchivePath(apksArchiveFile).setDeviceSpec(deviceSpecFile).setGetSizeSubCommand(GetSizeSubcommand.TOTAL).build();
assertThat(fromFlags).isEqualTo(fromBuilderApi);
}
use of com.android.bundle.Devices.DeviceSpec in project bundletool by google.
the class InstallApksCommandTest method badAbisDevice_throws.
@Test
@Theory
public void badAbisDevice_throws(@FromDataPoints("apksInDirectory") boolean apksInDirectory) throws Exception {
Path apksFile = createApks(createSimpleTableOfContent(ZipPath.create("base-master.apk")), apksInDirectory);
DeviceSpec deviceSpec = mergeSpecs(sdkVersion(21), density(480), abis(), locales("en-US"));
FakeDevice fakeDevice = FakeDevice.fromDeviceSpec(DEVICE_ID, DeviceState.ONLINE, deviceSpec);
AdbServer adbServer = new FakeAdbServer(/* hasInitialDeviceList= */
true, ImmutableList.of(fakeDevice));
InstallApksCommand command = InstallApksCommand.builder().setApksArchivePath(apksFile).setAdbPath(adbPath).setAdbServer(adbServer).build();
Throwable exception = assertThrows(IllegalStateException.class, () -> command.execute());
assertThat(exception).hasMessageThat().contains("Error retrieving device ABIs");
}
use of com.android.bundle.Devices.DeviceSpec in project bundletool by google.
the class InstallApksCommandTest method incompleteApksFile_missingAbiSplitMatchedForDevice_throws.
@Test
public void incompleteApksFile_missingAbiSplitMatchedForDevice_throws() throws Exception {
// Partial APK Set file where 'x86' split is included and 'x86_64' split is not included because
// device spec sent to 'build-apks' command doesn't support it.
// Next, device spec that should be matched to 'x86_64' split is provided to 'install-apks'
// command and command must throw IncompatibleDeviceException as mathed split 'x86_64' is not
// available.
BuildApksResult tableOfContent = BuildApksResult.newBuilder().setBundletool(Bundletool.newBuilder().setVersion(BundleToolVersion.getCurrentVersion().toString())).addVariant(createVariant(VariantTargeting.getDefaultInstance(), createSplitApkSet(/* moduleName= */
"base", createMasterApkDescription(ApkTargeting.getDefaultInstance(), ZipPath.create("base-master.apk")), splitApkDescription(apkAbiTargeting(X86, ImmutableSet.of(X86_64)), ZipPath.create("base-x86.apk"))))).build();
Path apksFile = createApks(tableOfContent, /* apksInDirectory= */
false);
DeviceSpec deviceSpec = mergeSpecs(sdkVersion(21), density(DensityAlias.MDPI), abis("x86_64", "x86"), locales("en-US"));
FakeDevice fakeDevice = FakeDevice.fromDeviceSpec(DEVICE_ID, DeviceState.ONLINE, deviceSpec);
AdbServer adbServer = new FakeAdbServer(/* hasInitialDeviceList= */
true, ImmutableList.of(fakeDevice));
InstallApksCommand command = InstallApksCommand.builder().setApksArchivePath(apksFile).setAdbPath(adbPath).setAdbServer(adbServer).build();
Throwable exception = assertThrows(IncompatibleDeviceException.class, command::execute);
assertThat(exception).hasMessageThat().contains("Missing APKs for [ABI] dimensions in the module 'base' for the provided device.");
}
use of com.android.bundle.Devices.DeviceSpec in project bundletool by google.
the class VariantMatcherTest method getAllMatchingVariants_partialDeviceSpec.
@Test
public void getAllMatchingVariants_partialDeviceSpec() {
ZipPath standaloneArmXxxhdpiApk = ZipPath.create("standalone-arm.xxxhdpi.apk");
ZipPath baseMasterSplitApk = ZipPath.create("base-master.apk");
ZipPath baseArmSplitApk = ZipPath.create("base-arm.apk");
ZipPath screenXxxhdpiApk = ZipPath.create("screen-xxxhdpi.apk");
Variant standaloneVariant = standaloneVariant(mergeVariantTargeting(variantSdkTargeting(sdkVersionFrom(1), ImmutableSet.of(sdkVersionFrom(21))), variantAbiTargeting(ARMEABI, ImmutableSet.of(X86)), variantDensityTargeting(XXXHDPI, ImmutableSet.of(MDPI))), mergeApkTargeting(apkAbiTargeting(ARMEABI, ImmutableSet.of(X86)), apkDensityTargeting(XXXHDPI, ImmutableSet.of(MDPI))), standaloneArmXxxhdpiApk);
Variant splitVariant = createVariant(variantSdkTargeting(sdkVersionFrom(21), ImmutableSet.of(sdkVersionFrom(1))), splitApkSet(/* moduleName= */
"base", splitApkDescription(ApkTargeting.getDefaultInstance(), baseMasterSplitApk), splitApkDescription(apkAbiTargeting(ARMEABI, ImmutableSet.of(X86)), baseArmSplitApk)), splitApkSet(/* moduleName= */
"screen", splitApkDescription(apkDensityTargeting(XXXHDPI, ImmutableSet.of(MDPI)), screenXxxhdpiApk)));
ImmutableList<Variant> variants = ImmutableList.of(standaloneVariant, splitVariant);
BuildApksResult buildApksResult = BuildApksResult.newBuilder().addAllVariant(variants).build();
DeviceSpec preLDevice = mergeSpecs(sdkVersion(19));
assertThat(new VariantMatcher(preLDevice).getAllMatchingVariants(buildApksResult)).containsExactly(standaloneVariant);
DeviceSpec preLXXXHDPIDevice = mergeSpecs(sdkVersion(19), density(XXXHDPI));
assertThat(new VariantMatcher(preLXXXHDPIDevice).getAllMatchingVariants(buildApksResult)).containsExactly(standaloneVariant);
DeviceSpec preLX86Device = mergeSpecs(sdkVersion(19), abis("x86"));
assertThat(new VariantMatcher(preLX86Device).getAllMatchingVariants(buildApksResult)).isEmpty();
DeviceSpec postLDevice = mergeSpecs(sdkVersion(21));
assertThat(new VariantMatcher(postLDevice).getAllMatchingVariants(buildApksResult)).containsExactly(splitVariant);
}
use of com.android.bundle.Devices.DeviceSpec in project bundletool by google.
the class VariantMatcherTest method getAllMatchingVariants_fullDeviceSpec.
@Test
public void getAllMatchingVariants_fullDeviceSpec() {
ZipPath standaloneX86MdpiApk = ZipPath.create("standalone-x86.mdpi.apk");
ZipPath baseMasterSplitApk = ZipPath.create("base-master.apk");
ZipPath baseArmSplitApk = ZipPath.create("base-arm.apk");
ZipPath screenXxxhdpiApk = ZipPath.create("screen-xxxhdpi.apk");
Variant standaloneX86MdpiVariant = standaloneVariant(mergeVariantTargeting(variantSdkTargeting(sdkVersionFrom(1), ImmutableSet.of(sdkVersionFrom(21))), variantAbiTargeting(X86, ImmutableSet.of(ARMEABI)), variantDensityTargeting(MDPI, ImmutableSet.of(XXXHDPI))), mergeApkTargeting(apkAbiTargeting(X86, ImmutableSet.of(ARMEABI)), apkDensityTargeting(MDPI, ImmutableSet.of(XXXHDPI))), standaloneX86MdpiApk);
Variant splitVariant = createVariant(variantSdkTargeting(sdkVersionFrom(21), ImmutableSet.of(sdkVersionFrom(1))), splitApkSet(/* moduleName= */
"base", splitApkDescription(ApkTargeting.getDefaultInstance(), baseMasterSplitApk), splitApkDescription(apkAbiTargeting(ARMEABI, ImmutableSet.of(X86)), baseArmSplitApk)), splitApkSet(/* moduleName= */
"screen", splitApkDescription(apkDensityTargeting(XXXHDPI, ImmutableSet.of(MDPI)), screenXxxhdpiApk)));
ImmutableList<Variant> variants = ImmutableList.of(standaloneX86MdpiVariant, splitVariant);
BuildApksResult buildApksResult = BuildApksResult.newBuilder().addAllVariant(variants).build();
DeviceSpec preLX86MdpiDevice = mergeSpecs(sdkVersion(19), abis("x86"), density(MDPI), locales("en"));
assertThat(new VariantMatcher(preLX86MdpiDevice).getAllMatchingVariants(buildApksResult)).containsExactly(standaloneX86MdpiVariant);
DeviceSpec preLX86HdpiDevice = mergeSpecs(sdkVersion(19), abis("x86"), density(HDPI), locales("en"));
assertThat(new VariantMatcher(preLX86HdpiDevice).getAllMatchingVariants(buildApksResult)).isEmpty();
DeviceSpec postLDevice = mergeSpecs(sdkVersion(21), abis("x86"), density(MDPI), locales("en"));
assertThat(new VariantMatcher(postLDevice).getAllMatchingVariants(buildApksResult)).containsExactly(splitVariant);
}
Aggregations