use of com.android.tools.build.bundletool.testing.FakeAdbServer in project bundletool by google.
the class BuildApksConnectedDeviceTest method connectedDevice_withDeviceId_correctSplitsGenerated.
@Test
public void connectedDevice_withDeviceId_correctSplitsGenerated() throws Exception {
fakeAdbServer = new FakeAdbServer(/* hasInitialDeviceList= */
true, ImmutableList.of(FakeDevice.fromDeviceSpec("id1", DeviceState.ONLINE, lDeviceWithDensity(DensityAlias.XHDPI)), FakeDevice.fromDeviceSpec("id2", DeviceState.ONLINE, lDeviceWithDensity(DensityAlias.MDPI))));
bundleSerializer.writeToDisk(createLdpiHdpiAppBundle(), bundlePath);
// We are picking the "id2" - MDPI device.
BuildApksCommand command = BuildApksCommand.builder().setBundlePath(bundlePath).setOutputFile(outputFilePath).setGenerateOnlyForConnectedDevice(true).setAdbPath(sdkDirPath.resolve("platform-tools").resolve("adb")).setAdbServer(fakeAdbServer).setDeviceId("id2").build();
Path apksArchive = command.execute();
BuildApksResult result;
try (ZipFile apksZipFile = new ZipFile(apksArchive.toFile())) {
assertThat(apksZipFile).containsExactlyEntries("toc.pb", "splits/base-master.apk", "splits/base-mdpi.apk");
result = extractTocFromApkSetFile(apksZipFile, outputDir);
}
assertThat(result.getVariantList()).hasSize(1);
Variant variant = result.getVariant(0);
assertThat(variant.getApkSetList()).hasSize(1);
ApkSet apkSet = variant.getApkSet(0);
// One master and one density split.
assertThat(apkSet.getApkDescriptionList()).hasSize(2);
assertThat(apkNamesInSet(apkSet)).containsExactly("splits/base-master.apk", "splits/base-mdpi.apk");
}
use of com.android.tools.build.bundletool.testing.FakeAdbServer in project bundletool by google.
the class BuildApksConnectedDeviceTest method connectedDevice_universalApk_throws.
@Test
public void connectedDevice_universalApk_throws() throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", module -> module.setManifest(androidManifest("com.app"))).build();
bundleSerializer.writeToDisk(appBundle, bundlePath);
BuildApksCommand.Builder command = BuildApksCommand.builder().setBundlePath(bundlePath).setOutputFile(outputFilePath).setGenerateOnlyForConnectedDevice(true).setApkBuildMode(UNIVERSAL).setAdbPath(sdkDirPath.resolve("platform-tools").resolve("adb")).setAdbServer(fakeAdbServer);
Throwable exception = assertThrows(InvalidCommandException.class, command::build);
assertThat(exception).hasMessageThat().contains("Optimizing for connected device only possible when running with 'default' mode flag.");
}
use of com.android.tools.build.bundletool.testing.FakeAdbServer in project bundletool by google.
the class BuildApksConnectedDeviceTest method connectedDeviceL_bundleTargetsMPlus_throws.
@Ignore("Re-enable when minSdk version propagation is fixed.")
@Test
public void connectedDeviceL_bundleTargetsMPlus_throws() throws Exception {
fakeAdbServer = new FakeAdbServer(/* hasInitialDeviceList= */
true, ImmutableList.of(FakeDevice.fromDeviceSpec("id1", DeviceState.ONLINE, mergeSpecs(sdkVersion(/* Lollipop */
21), abis("x86"), locales("en-US"), density(DensityAlias.XHDPI)))));
bundleSerializer.writeToDisk(createMinSdkBundle(/* Marshmallow */
23), bundlePath);
BuildApksCommand command = BuildApksCommand.builder().setBundlePath(bundlePath).setOutputFile(outputFilePath).setGenerateOnlyForConnectedDevice(true).setAdbPath(sdkDirPath.resolve("platform-tools").resolve("adb")).setAdbServer(fakeAdbServer).build();
Throwable exception = assertThrows(CommandExecutionException.class, () -> command.execute());
assertThat(exception).hasMessageThat().contains("");
}
use of com.android.tools.build.bundletool.testing.FakeAdbServer in project bundletool by google.
the class BuildApksConnectedDeviceTest method connectedDevice_noDevicesFound_throws.
@Test
public void connectedDevice_noDevicesFound_throws() throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", module -> module.setManifest(androidManifest("com.app"))).build();
bundleSerializer.writeToDisk(appBundle, bundlePath);
BuildApksCommand command = BuildApksCommand.builder().setBundlePath(bundlePath).setOutputFile(outputFilePath).setGenerateOnlyForConnectedDevice(true).setAdbPath(sdkDirPath.resolve("platform-tools").resolve("adb")).setAdbServer(fakeAdbServer).build();
Throwable exception = assertThrows(CommandExecutionException.class, () -> command.execute());
assertThat(exception).hasMessageThat().contains("No connected devices found.");
}
use of com.android.tools.build.bundletool.testing.FakeAdbServer in project bundletool by google.
the class InstallApksCommandTest method badSdkVersionDevice_throws.
@Test
public void badSdkVersionDevice_throws() throws Exception {
DeviceSpec deviceSpec = mergeSpecs(sdkVersion(1), density(480), 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(simpleApksPath).setAdbPath(adbPath).setAdbServer(adbServer).build();
Throwable exception = assertThrows(IllegalStateException.class, () -> command.execute());
assertThat(exception).hasMessageThat().contains("Error retrieving device SDK version");
}
Aggregations