Search in sources :

Example 6 with FakeAdbServer

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");
}
Also used : Path(java.nio.file.Path) Variant(com.android.bundle.Commands.Variant) ApkSet(com.android.bundle.Commands.ApkSet) ZipFile(java.util.zip.ZipFile) BuildApksResult(com.android.bundle.Commands.BuildApksResult) FakeAdbServer(com.android.tools.build.bundletool.testing.FakeAdbServer) Test(org.junit.Test)

Example 7 with FakeAdbServer

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.");
}
Also used : AppBundleFactory.createLdpiHdpiAppBundle(com.android.tools.build.bundletool.testing.AppBundleFactory.createLdpiHdpiAppBundle) UNIVERSAL(com.android.tools.build.bundletool.commands.BuildApksCommand.ApkBuildMode.UNIVERSAL) DeviceState(com.android.ddmlib.IDevice.DeviceState) ManifestProtoUtils.androidManifest(com.android.tools.build.bundletool.testing.ManifestProtoUtils.androidManifest) Variant(com.android.bundle.Commands.Variant) DeviceFactory.abis(com.android.tools.build.bundletool.testing.DeviceFactory.abis) DensityAlias(com.android.bundle.Targeting.ScreenDensity.DensityAlias) ZipFile(java.util.zip.ZipFile) Path(java.nio.file.Path) FakeSystemEnvironmentProvider(com.android.tools.build.bundletool.testing.FakeSystemEnvironmentProvider) ImmutableMap(com.google.common.collect.ImmutableMap) CommandExecutionException(com.android.tools.build.bundletool.model.exceptions.CommandExecutionException) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) FlagParser(com.android.tools.build.bundletool.flags.FlagParser) DeviceFactory.sdkVersion(com.android.tools.build.bundletool.testing.DeviceFactory.sdkVersion) ApkSet(com.android.bundle.Commands.ApkSet) SystemEnvironmentProvider(com.android.tools.build.bundletool.model.utils.SystemEnvironmentProvider) AppBundleBuilder(com.android.tools.build.bundletool.testing.AppBundleBuilder) DeviceFactory.density(com.android.tools.build.bundletool.testing.DeviceFactory.density) TruthZip.assertThat(com.android.tools.build.bundletool.testing.truth.zip.TruthZip.assertThat) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) DeviceFactory.locales(com.android.tools.build.bundletool.testing.DeviceFactory.locales) RunWith(org.junit.runner.RunWith) BuildApksResult(com.android.bundle.Commands.BuildApksResult) DeviceFactory.mergeSpecs(com.android.tools.build.bundletool.testing.DeviceFactory.mergeSpecs) ApkSetUtils.extractTocFromApkSetFile(com.android.tools.build.bundletool.testing.ApkSetUtils.extractTocFromApkSetFile) ImmutableList(com.google.common.collect.ImmutableList) AppBundleSerializer(com.android.tools.build.bundletool.io.AppBundleSerializer) ApkDescription(com.android.bundle.Commands.ApkDescription) DeviceFactory.lDeviceWithDensity(com.android.tools.build.bundletool.testing.DeviceFactory.lDeviceWithDensity) ANDROID_HOME(com.android.tools.build.bundletool.testing.FakeSystemEnvironmentProvider.ANDROID_HOME) AdbServer(com.android.tools.build.bundletool.device.AdbServer) Before(org.junit.Before) AppBundleFactory.createMinMaxSdkAppBundle(com.android.tools.build.bundletool.testing.AppBundleFactory.createMinMaxSdkAppBundle) AppBundleFactory.createX86AppBundle(com.android.tools.build.bundletool.testing.AppBundleFactory.createX86AppBundle) Files(java.nio.file.Files) FakeDevice(com.android.tools.build.bundletool.testing.FakeDevice) Test(org.junit.Test) JUnit4(org.junit.runners.JUnit4) Truth.assertThat(com.google.common.truth.Truth.assertThat) AppBundleFactory.createMinSdkBundle(com.android.tools.build.bundletool.testing.AppBundleFactory.createMinSdkBundle) Rule(org.junit.Rule) Ignore(org.junit.Ignore) FakeAdbServer(com.android.tools.build.bundletool.testing.FakeAdbServer) AppBundleFactory.createMaxSdkBundle(com.android.tools.build.bundletool.testing.AppBundleFactory.createMaxSdkBundle) IncompatibleDeviceException(com.android.tools.build.bundletool.model.exceptions.IncompatibleDeviceException) InvalidCommandException(com.android.tools.build.bundletool.model.exceptions.InvalidCommandException) AppBundle(com.android.tools.build.bundletool.model.AppBundle) TemporaryFolder(org.junit.rules.TemporaryFolder) AppBundleFactory.createLdpiHdpiAppBundle(com.android.tools.build.bundletool.testing.AppBundleFactory.createLdpiHdpiAppBundle) AppBundleFactory.createMinMaxSdkAppBundle(com.android.tools.build.bundletool.testing.AppBundleFactory.createMinMaxSdkAppBundle) AppBundleFactory.createX86AppBundle(com.android.tools.build.bundletool.testing.AppBundleFactory.createX86AppBundle) AppBundle(com.android.tools.build.bundletool.model.AppBundle) AppBundleBuilder(com.android.tools.build.bundletool.testing.AppBundleBuilder) Test(org.junit.Test)

Example 8 with FakeAdbServer

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("");
}
Also used : FakeAdbServer(com.android.tools.build.bundletool.testing.FakeAdbServer) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 9 with FakeAdbServer

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.");
}
Also used : AppBundleFactory.createLdpiHdpiAppBundle(com.android.tools.build.bundletool.testing.AppBundleFactory.createLdpiHdpiAppBundle) UNIVERSAL(com.android.tools.build.bundletool.commands.BuildApksCommand.ApkBuildMode.UNIVERSAL) DeviceState(com.android.ddmlib.IDevice.DeviceState) ManifestProtoUtils.androidManifest(com.android.tools.build.bundletool.testing.ManifestProtoUtils.androidManifest) Variant(com.android.bundle.Commands.Variant) DeviceFactory.abis(com.android.tools.build.bundletool.testing.DeviceFactory.abis) DensityAlias(com.android.bundle.Targeting.ScreenDensity.DensityAlias) ZipFile(java.util.zip.ZipFile) Path(java.nio.file.Path) FakeSystemEnvironmentProvider(com.android.tools.build.bundletool.testing.FakeSystemEnvironmentProvider) ImmutableMap(com.google.common.collect.ImmutableMap) CommandExecutionException(com.android.tools.build.bundletool.model.exceptions.CommandExecutionException) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) FlagParser(com.android.tools.build.bundletool.flags.FlagParser) DeviceFactory.sdkVersion(com.android.tools.build.bundletool.testing.DeviceFactory.sdkVersion) ApkSet(com.android.bundle.Commands.ApkSet) SystemEnvironmentProvider(com.android.tools.build.bundletool.model.utils.SystemEnvironmentProvider) AppBundleBuilder(com.android.tools.build.bundletool.testing.AppBundleBuilder) DeviceFactory.density(com.android.tools.build.bundletool.testing.DeviceFactory.density) TruthZip.assertThat(com.android.tools.build.bundletool.testing.truth.zip.TruthZip.assertThat) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) DeviceFactory.locales(com.android.tools.build.bundletool.testing.DeviceFactory.locales) RunWith(org.junit.runner.RunWith) BuildApksResult(com.android.bundle.Commands.BuildApksResult) DeviceFactory.mergeSpecs(com.android.tools.build.bundletool.testing.DeviceFactory.mergeSpecs) ApkSetUtils.extractTocFromApkSetFile(com.android.tools.build.bundletool.testing.ApkSetUtils.extractTocFromApkSetFile) ImmutableList(com.google.common.collect.ImmutableList) AppBundleSerializer(com.android.tools.build.bundletool.io.AppBundleSerializer) ApkDescription(com.android.bundle.Commands.ApkDescription) DeviceFactory.lDeviceWithDensity(com.android.tools.build.bundletool.testing.DeviceFactory.lDeviceWithDensity) ANDROID_HOME(com.android.tools.build.bundletool.testing.FakeSystemEnvironmentProvider.ANDROID_HOME) AdbServer(com.android.tools.build.bundletool.device.AdbServer) Before(org.junit.Before) AppBundleFactory.createMinMaxSdkAppBundle(com.android.tools.build.bundletool.testing.AppBundleFactory.createMinMaxSdkAppBundle) AppBundleFactory.createX86AppBundle(com.android.tools.build.bundletool.testing.AppBundleFactory.createX86AppBundle) Files(java.nio.file.Files) FakeDevice(com.android.tools.build.bundletool.testing.FakeDevice) Test(org.junit.Test) JUnit4(org.junit.runners.JUnit4) Truth.assertThat(com.google.common.truth.Truth.assertThat) AppBundleFactory.createMinSdkBundle(com.android.tools.build.bundletool.testing.AppBundleFactory.createMinSdkBundle) Rule(org.junit.Rule) Ignore(org.junit.Ignore) FakeAdbServer(com.android.tools.build.bundletool.testing.FakeAdbServer) AppBundleFactory.createMaxSdkBundle(com.android.tools.build.bundletool.testing.AppBundleFactory.createMaxSdkBundle) IncompatibleDeviceException(com.android.tools.build.bundletool.model.exceptions.IncompatibleDeviceException) InvalidCommandException(com.android.tools.build.bundletool.model.exceptions.InvalidCommandException) AppBundle(com.android.tools.build.bundletool.model.AppBundle) TemporaryFolder(org.junit.rules.TemporaryFolder) AppBundleFactory.createLdpiHdpiAppBundle(com.android.tools.build.bundletool.testing.AppBundleFactory.createLdpiHdpiAppBundle) AppBundleFactory.createMinMaxSdkAppBundle(com.android.tools.build.bundletool.testing.AppBundleFactory.createMinMaxSdkAppBundle) AppBundleFactory.createX86AppBundle(com.android.tools.build.bundletool.testing.AppBundleFactory.createX86AppBundle) AppBundle(com.android.tools.build.bundletool.model.AppBundle) AppBundleBuilder(com.android.tools.build.bundletool.testing.AppBundleBuilder) Test(org.junit.Test)

Example 10 with FakeAdbServer

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");
}
Also used : DeviceSpec(com.android.bundle.Devices.DeviceSpec) FakeDevice(com.android.tools.build.bundletool.testing.FakeDevice) AdbServer(com.android.tools.build.bundletool.device.AdbServer) FakeAdbServer(com.android.tools.build.bundletool.testing.FakeAdbServer) FakeAdbServer(com.android.tools.build.bundletool.testing.FakeAdbServer) Test(org.junit.Test)

Aggregations

FakeAdbServer (com.android.tools.build.bundletool.testing.FakeAdbServer)57 Test (org.junit.Test)57 FakeDevice (com.android.tools.build.bundletool.testing.FakeDevice)30 Path (java.nio.file.Path)27 AdbServer (com.android.tools.build.bundletool.device.AdbServer)23 BuildApksResult (com.android.bundle.Commands.BuildApksResult)19 ZipPath (com.android.tools.build.bundletool.model.ZipPath)16 DeviceSpec (com.android.bundle.Devices.DeviceSpec)14 ArrayList (java.util.ArrayList)10 Theory (org.junit.experimental.theories.Theory)9 ApkSet (com.android.bundle.Commands.ApkSet)7 Variant (com.android.bundle.Commands.Variant)7 DeviceState (com.android.ddmlib.IDevice.DeviceState)7 CommandExecutionException (com.android.tools.build.bundletool.model.exceptions.CommandExecutionException)7 ImmutableList (com.google.common.collect.ImmutableList)7 Truth.assertThat (com.google.common.truth.Truth.assertThat)7 Files (java.nio.file.Files)7 ZipFile (java.util.zip.ZipFile)7 Before (org.junit.Before)7 Rule (org.junit.Rule)7