use of com.android.bundle.Devices.DeviceSpec in project bundletool by google.
the class InstallApksCommandTest method deviceAbiIncompatible_throws.
@Test
public void deviceAbiIncompatible_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(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));
FakeDevice fakeDevice = FakeDevice.fromDeviceSpec(DEVICE_ID, DeviceState.ONLINE, deviceSpec);
AdbServer adbServer = new FakeAdbServer(/* hasInitialDeviceList= */
true, ImmutableList.of(fakeDevice));
InstallApksCommand command = InstallApksCommand.builder().setApksArchivePath(apksArchiveFile).setAdbPath(adbPath).setAdbServer(adbServer).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 InstallApksCommandTest method badDensityDevice_throws.
@Test
@Theory
public void badDensityDevice_throws(@FromDataPoints("apksInDirectory") boolean apksInDirectory) throws Exception {
Path apksFile = createApks(createSimpleTableOfContent(ZipPath.create("base-master.apk")), apksInDirectory);
DeviceSpec deviceSpec = mergeSpecs(sdkVersion(21), density(-1), 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(IllegalStateException.class, () -> command.execute());
assertThat(exception).hasMessageThat().contains("Error retrieving device density");
}
use of com.android.bundle.Devices.DeviceSpec in project bundletool by google.
the class ApkMatcherTest method apkMatch_withModuleNameFiltering_standaloneApkMatches_throws.
@Test
public void apkMatch_withModuleNameFiltering_standaloneApkMatches_throws() {
DeviceSpec x86Device = lDeviceWithAbis("x86");
ZipPath apk = ZipPath.create("master-x86.apk");
BuildApksResult buildApksResult = buildApksResult(standaloneVariant(variantAbiTargeting(X86), apkAbiTargeting(X86), apk));
// Sanity-check that the device matches the standalone APK.
assertThat(new ApkMatcher(x86Device).getMatchingApks(buildApksResult)).containsExactly(baseMatchedApk(apk));
Optional<ImmutableSet<String>> baseModuleOnly = Optional.of(ImmutableSet.of("base"));
InvalidCommandException exception = assertThrows(InvalidCommandException.class, () -> createMatcher(x86Device, baseModuleOnly).getMatchingApks(buildApksResult));
assertThat(exception).hasMessageThat().contains("Cannot restrict modules");
}
use of com.android.bundle.Devices.DeviceSpec in project bundletool by google.
the class ApkMatcherTest method apkMatch_withModuleNameFiltering_splitApks_checksModuleName.
// Module name filtering.
@Test
public void apkMatch_withModuleNameFiltering_splitApks_checksModuleName() {
DeviceSpec device = deviceWithSdk(21);
ZipPath apk = ZipPath.create("master-de-fr.apk");
BuildApksResult buildApksResult = buildApksResult(createVariant(VariantTargeting.getDefaultInstance(), splitApkSet(/* moduleName= */
"base", splitApkDescription(ApkTargeting.getDefaultInstance(), apk))));
Optional<ImmutableSet<String>> allModules = Optional.empty();
assertThat(createMatcher(device, allModules).getMatchingApks(buildApksResult)).containsExactly(baseMatchedApk(apk));
Optional<ImmutableSet<String>> baseModuleOnly = Optional.of(ImmutableSet.of("base"));
assertThat(createMatcher(device, baseModuleOnly).getMatchingApks(buildApksResult)).containsExactly(baseMatchedApk(apk));
Optional<ImmutableSet<String>> unknownModuleOnly = Optional.of(ImmutableSet.of("unknown_module"));
InvalidCommandException exception = assertThrows(InvalidCommandException.class, () -> createMatcher(device, unknownModuleOnly).getMatchingApks(buildApksResult));
assertThat(exception).hasMessageThat().contains("The APK Set archive does not contain the following modules: [unknown_module]");
}
use of com.android.bundle.Devices.DeviceSpec in project bundletool by google.
the class ApkMatcherTest method apkMatch_withModuleNameFiltering_splitApks_moduleWithDependency.
@Test
public void apkMatch_withModuleNameFiltering_splitApks_moduleWithDependency() {
DeviceSpec device = deviceWithSdk(21);
ZipPath baseApk = ZipPath.create("master-base.apk");
ZipPath feature1Apk = ZipPath.create("master-feature1.apk");
ZipPath feature2Apk = ZipPath.create("master-feature2.apk");
BuildApksResult buildApksResult = buildApksResult(createVariant(VariantTargeting.getDefaultInstance(), splitApkSet(/* moduleName= */
"base", splitApkDescription(ApkTargeting.getDefaultInstance(), baseApk)), splitApkSet(/* moduleName= */
"feature1", DeliveryType.ON_DEMAND, /* moduleDependencies= */
ImmutableList.of(), splitApkDescription(ApkTargeting.getDefaultInstance(), feature1Apk)), splitApkSet(/* moduleName= */
"feature2", DeliveryType.ON_DEMAND, /* moduleDependencies= */
ImmutableList.of("feature1"), splitApkDescription(ApkTargeting.getDefaultInstance(), feature2Apk))));
// By default on-demand features are not installed.
Optional<ImmutableSet<String>> allModules = Optional.empty();
assertThat(createMatcher(device, allModules).getMatchingApks(buildApksResult)).containsExactly(baseMatchedApk(baseApk));
Optional<ImmutableSet<String>> baseModuleOnly = Optional.of(ImmutableSet.of("base"));
assertThat(createMatcher(device, baseModuleOnly).getMatchingApks(buildApksResult)).containsExactly(baseMatchedApk(baseApk));
Optional<ImmutableSet<String>> feature2ModuleOnly = Optional.of(ImmutableSet.of("feature2"));
assertThat(createMatcher(device, feature2ModuleOnly).getMatchingApks(buildApksResult)).containsExactly(baseMatchedApk(baseApk), matchedApk(feature1Apk, /* moduleName=*/
"feature1", ON_DEMAND), matchedApk(feature2Apk, /* moduleName=*/
"feature2", ON_DEMAND));
Optional<ImmutableSet<String>> feature1ModuleOnly = Optional.of(ImmutableSet.of("feature1"));
assertThat(createMatcher(device, feature1ModuleOnly).getMatchingApks(buildApksResult)).containsExactly(baseMatchedApk(baseApk), matchedApk(feature1Apk, /* moduleName=*/
"feature1", ON_DEMAND));
}
Aggregations