use of com.android.tools.build.bundletool.testing.FakeAdbServer in project bundletool by google.
the class BuildApksConnectedDeviceTest method connectedDevice_moreThanOneDevice_throws.
@Test
public void connectedDevice_moreThanOneDevice_throws() throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", module -> module.setManifest(androidManifest("com.app"))).build();
bundleSerializer.writeToDisk(appBundle, bundlePath);
fakeAdbServer = new FakeAdbServer(/* hasInitialDeviceList= */
true, ImmutableList.of(FakeDevice.fromDeviceSpec("id1", DeviceState.ONLINE, lDeviceWithDensity(DensityAlias.XHDPI)), FakeDevice.fromDeviceSpec("id2", DeviceState.ONLINE, lDeviceWithDensity(DensityAlias.MDPI))));
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("More than one device connected, please provide --device-id.");
}
use of com.android.tools.build.bundletool.testing.FakeAdbServer in project bundletool by google.
the class BuildApksConnectedDeviceTest method connectedDevice_correctStandaloneGenerated.
@Test
public void connectedDevice_correctStandaloneGenerated() throws Exception {
fakeAdbServer = new FakeAdbServer(/* hasInitialDeviceList= */
true, ImmutableList.of(FakeDevice.fromDeviceSpec("id1", DeviceState.ONLINE, mergeSpecs(sdkVersion(19), abis("x86"), locales("en-US"), density(DensityAlias.HDPI)))));
bundleSerializer.writeToDisk(createLdpiHdpiAppBundle(), bundlePath);
BuildApksCommand command = BuildApksCommand.builder().setBundlePath(bundlePath).setOutputFile(outputFilePath).setGenerateOnlyForConnectedDevice(true).setAdbPath(sdkDirPath.resolve("platform-tools").resolve("adb")).setAdbServer(fakeAdbServer).build();
Path apksArchive = command.execute();
BuildApksResult result;
try (ZipFile apksZipFile = new ZipFile(apksArchive.toFile())) {
assertThat(apksZipFile).containsExactlyEntries("toc.pb", "standalones/standalone-hdpi.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 standalone APK.
assertThat(apkSet.getApkDescriptionList()).hasSize(1);
assertThat(apkNamesInSet(apkSet)).containsExactly("standalones/standalone-hdpi.apk");
}
use of com.android.tools.build.bundletool.testing.FakeAdbServer in project bundletool by google.
the class BuildApksConnectedDeviceTest method connectedDevicePreL_bundleTargetsLPlus_throws.
@Test
public void connectedDevicePreL_bundleTargetsLPlus_throws() throws Exception {
fakeAdbServer = new FakeAdbServer(/* hasInitialDeviceList= */
true, ImmutableList.of(FakeDevice.fromDeviceSpec("id1", DeviceState.ONLINE, mergeSpecs(sdkVersion(/* KitKat */
19), abis("x86"), locales("en-US"), density(DensityAlias.XHDPI)))));
bundleSerializer.writeToDisk(createMinSdkBundle(21), bundlePath);
BuildApksCommand command = BuildApksCommand.builder().setBundlePath(bundlePath).setOutputFile(outputFilePath).setGenerateOnlyForConnectedDevice(true).setAdbPath(sdkDirPath.resolve("platform-tools").resolve("adb")).setAdbServer(fakeAdbServer).build();
Throwable exception = assertThrows(IncompatibleDeviceException.class, command::execute);
assertThat(exception).hasMessageThat().contains("App Bundle targets L+ devices, but the device has SDK version lower than L.");
}
use of com.android.tools.build.bundletool.testing.FakeAdbServer in project bundletool by google.
the class BuildApksConnectedDeviceTest method connectedDevice_withDeviceId_correctStandaloneGenerated.
@Test
public void connectedDevice_withDeviceId_correctStandaloneGenerated() throws Exception {
fakeAdbServer = new FakeAdbServer(/* hasInitialDeviceList= */
true, ImmutableList.of(FakeDevice.fromDeviceSpec("id1", DeviceState.ONLINE, mergeSpecs(sdkVersion(19), abis("x86"), locales("en-US"), density(DensityAlias.XHDPI))), FakeDevice.fromDeviceSpec("id2", DeviceState.ONLINE, lDeviceWithDensity(DensityAlias.XXHDPI))));
bundleSerializer.writeToDisk(createLdpiHdpiAppBundle(), bundlePath);
// Selecting "id1" device - KitKat, XHDPI.
BuildApksCommand command = BuildApksCommand.builder().setBundlePath(bundlePath).setOutputFile(outputFilePath).setGenerateOnlyForConnectedDevice(true).setAdbPath(sdkDirPath.resolve("platform-tools").resolve("adb")).setAdbServer(fakeAdbServer).setDeviceId("id1").build();
Path apksArchive = command.execute();
BuildApksResult result;
try (ZipFile apksZipFile = new ZipFile(apksArchive.toFile())) {
assertThat(apksZipFile).containsExactlyEntries("toc.pb", "standalones/standalone-xhdpi.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 standalone APK.
assertThat(apkSet.getApkDescriptionList()).hasSize(1);
assertThat(apkNamesInSet(apkSet)).containsExactly("standalones/standalone-xhdpi.apk");
}
use of com.android.tools.build.bundletool.testing.FakeAdbServer in project bundletool by google.
the class BuildApksConnectedDeviceTest method connectedDevice_correctSplitsGenerated.
@Test
public void connectedDevice_correctSplitsGenerated() throws Exception {
fakeAdbServer = new FakeAdbServer(/* hasInitialDeviceList= */
true, ImmutableList.of(FakeDevice.fromDeviceSpec("id1", DeviceState.ONLINE, lDeviceWithDensity(DensityAlias.XHDPI))));
bundleSerializer.writeToDisk(createLdpiHdpiAppBundle(), bundlePath);
BuildApksCommand command = BuildApksCommand.builder().setBundlePath(bundlePath).setOutputFile(outputFilePath).setGenerateOnlyForConnectedDevice(true).setAdbPath(sdkDirPath.resolve("platform-tools").resolve("adb")).setAdbServer(fakeAdbServer).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-xhdpi.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-xhdpi.apk");
}
Aggregations