Search in sources :

Example 11 with DeviceSpec

use of com.android.bundle.Devices.DeviceSpec in project bundletool by google.

the class BuildApksDeviceSpecTest method deviceSpecFlags_inJavaViaProtos_equivalent.

@Test
public void deviceSpecFlags_inJavaViaProtos_equivalent() throws Exception {
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    DeviceSpec deviceSpec = deviceWithSdk(28);
    Path deviceSpecPath = createDeviceSpecFile(deviceSpec, tmpDir.resolve("device.json"));
    BuildApksCommand commandViaFlags = BuildApksCommand.fromFlags(new FlagParser().parse("--bundle=" + bundlePath, "--output=" + outputFilePath, "--device-spec=" + deviceSpecPath), new PrintStream(output), systemEnvironmentProvider, fakeAdbServer);
    BuildApksCommand.Builder commandViaBuilder = BuildApksCommand.builder().setBundlePath(bundlePath).setOutputFile(outputFilePath).setDeviceSpec(deviceSpec).setExecutorServiceInternal(commandViaFlags.getExecutorService()).setExecutorServiceCreatedByBundleTool(true).setOutputPrintStream(commandViaFlags.getOutputPrintStream().get());
    DebugKeystoreUtils.getDebugSigningConfiguration(systemEnvironmentProvider).ifPresent(commandViaBuilder::setSigningConfiguration);
    assertThat(commandViaBuilder.build()).isEqualTo(commandViaFlags);
}
Also used : DeviceSpec(com.android.bundle.Devices.DeviceSpec) Path(java.nio.file.Path) PrintStream(java.io.PrintStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FlagParser(com.android.tools.build.bundletool.flags.FlagParser) Test(org.junit.Test)

Example 12 with DeviceSpec

use of com.android.bundle.Devices.DeviceSpec in project bundletool by google.

the class BuildApksDeviceSpecTest method deviceSpecL_bundleTargetsPreL_throws.

@Test
public void deviceSpecL_bundleTargetsPreL_throws() throws Exception {
    bundleSerializer.writeToDisk(createMaxSdkBundle(/* KitKat */
    19), bundlePath);
    DeviceSpec deviceSpec = lDeviceWithDensity(XHDPI);
    BuildApksCommand command = BuildApksCommand.builder().setBundlePath(bundlePath).setOutputFile(outputFilePath).setDeviceSpec(deviceSpec).build();
    Throwable exception = assertThrows(IncompatibleDeviceException.class, command::execute);
    assertThat(exception).hasMessageThat().contains("App Bundle targets pre-L devices, but the device has SDK version " + "higher or equal to L.");
}
Also used : DeviceSpec(com.android.bundle.Devices.DeviceSpec) Test(org.junit.Test)

Example 13 with DeviceSpec

use of com.android.bundle.Devices.DeviceSpec in project bundletool by google.

the class BuildApksDeviceSpecTest method deviceSpecFlags_inJavaViaFiles_equivalent.

@Test
public void deviceSpecFlags_inJavaViaFiles_equivalent() throws Exception {
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    DeviceSpec deviceSpec = deviceWithSdk(28);
    Path deviceSpecPath = createDeviceSpecFile(deviceSpec, tmpDir.resolve("device.json"));
    BuildApksCommand commandViaFlags = BuildApksCommand.fromFlags(new FlagParser().parse("--bundle=" + bundlePath, "--output=" + outputFilePath, "--device-spec=" + deviceSpecPath), new PrintStream(output), systemEnvironmentProvider, fakeAdbServer);
    BuildApksCommand.Builder commandViaBuilder = BuildApksCommand.builder().setBundlePath(bundlePath).setOutputFile(outputFilePath).setDeviceSpec(deviceSpecPath).setExecutorServiceInternal(commandViaFlags.getExecutorService()).setExecutorServiceCreatedByBundleTool(true).setOutputPrintStream(commandViaFlags.getOutputPrintStream().get());
    DebugKeystoreUtils.getDebugSigningConfiguration(systemEnvironmentProvider).ifPresent(commandViaBuilder::setSigningConfiguration);
    assertThat(commandViaBuilder.build()).isEqualTo(commandViaFlags);
}
Also used : DeviceSpec(com.android.bundle.Devices.DeviceSpec) Path(java.nio.file.Path) PrintStream(java.io.PrintStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FlagParser(com.android.tools.build.bundletool.flags.FlagParser) Test(org.junit.Test)

Example 14 with DeviceSpec

use of com.android.bundle.Devices.DeviceSpec in project bundletool by google.

the class BuildApksDeviceSpecTest method deviceSpec_systemApkMode_partialDeviceSpecMissingAbi_throws.

@Test
@Theory
public void deviceSpec_systemApkMode_partialDeviceSpecMissingAbi_throws() throws Exception {
    DeviceSpec deviceSpec = mergeSpecs(density(DensityAlias.MDPI));
    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).setDeviceSpec(deviceSpec).setApkBuildMode(SYSTEM);
    Throwable exception = assertThrows(InvalidCommandException.class, command::build);
    assertThat(exception).hasMessageThat().contains("Device spec must have screen density and ABIs set when running with 'system' mode" + " flag.");
}
Also used : DeviceSpec(com.android.bundle.Devices.DeviceSpec) AppBundleFactory.createLdpiHdpiAppBundle(com.android.tools.build.bundletool.testing.AppBundleFactory.createLdpiHdpiAppBundle) SYSTEM(com.android.tools.build.bundletool.commands.BuildApksCommand.ApkBuildMode.SYSTEM) UNIVERSAL(com.android.tools.build.bundletool.commands.BuildApksCommand.ApkBuildMode.UNIVERSAL) ManifestProtoUtils.androidManifest(com.android.tools.build.bundletool.testing.ManifestProtoUtils.androidManifest) Variant(com.android.bundle.Commands.Variant) DeviceFactory.createDeviceSpecFile(com.android.tools.build.bundletool.testing.DeviceFactory.createDeviceSpecFile) DeviceSpec(com.android.bundle.Devices.DeviceSpec) 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) Theory(org.junit.experimental.theories.Theory) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) AppBundleFactory.createInstantBundle(com.android.tools.build.bundletool.testing.AppBundleFactory.createInstantBundle) 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) DeviceFactory.deviceWithSdk(com.android.tools.build.bundletool.testing.DeviceFactory.deviceWithSdk) ByteArrayOutputStream(java.io.ByteArrayOutputStream) RunWith(org.junit.runner.RunWith) BuildApksResult(com.android.bundle.Commands.BuildApksResult) DeviceFactory.mergeSpecs(com.android.tools.build.bundletool.testing.DeviceFactory.mergeSpecs) HDPI(com.android.bundle.Targeting.ScreenDensity.DensityAlias.HDPI) ApkSetUtils.extractTocFromApkSetFile(com.android.tools.build.bundletool.testing.ApkSetUtils.extractTocFromApkSetFile) ImmutableList(com.google.common.collect.ImmutableList) Theories(org.junit.experimental.theories.Theories) ResultUtils.instantApkVariants(com.android.tools.build.bundletool.model.utils.ResultUtils.instantApkVariants) AppBundleSerializer(com.android.tools.build.bundletool.io.AppBundleSerializer) ApkDescription(com.android.bundle.Commands.ApkDescription) ResultUtils.splitApkVariants(com.android.tools.build.bundletool.model.utils.ResultUtils.splitApkVariants) DeviceFactory.lDeviceWithDensity(com.android.tools.build.bundletool.testing.DeviceFactory.lDeviceWithDensity) AdbServer(com.android.tools.build.bundletool.device.AdbServer) Before(org.junit.Before) AppBundleFactory.createMinMaxSdkAppBundle(com.android.tools.build.bundletool.testing.AppBundleFactory.createMinMaxSdkAppBundle) PrintStream(java.io.PrintStream) AppBundleFactory.createX86AppBundle(com.android.tools.build.bundletool.testing.AppBundleFactory.createX86AppBundle) Test(org.junit.Test) Truth.assertThat(com.google.common.truth.Truth.assertThat) AppBundleFactory.createMinSdkBundle(com.android.tools.build.bundletool.testing.AppBundleFactory.createMinSdkBundle) XHDPI(com.android.bundle.Targeting.ScreenDensity.DensityAlias.XHDPI) Rule(org.junit.Rule) 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) Theory(org.junit.experimental.theories.Theory)

Example 15 with DeviceSpec

use of com.android.bundle.Devices.DeviceSpec 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

DeviceSpec (com.android.bundle.Devices.DeviceSpec)124 Test (org.junit.Test)113 Path (java.nio.file.Path)71 BuildApksResult (com.android.bundle.Commands.BuildApksResult)68 ZipPath (com.android.tools.build.bundletool.model.ZipPath)64 FakeAdbServer (com.android.tools.build.bundletool.testing.FakeAdbServer)19 FlagParser (com.android.tools.build.bundletool.flags.FlagParser)18 AdbServer (com.android.tools.build.bundletool.device.AdbServer)15 ImmutableSet (com.google.common.collect.ImmutableSet)14 Theory (org.junit.experimental.theories.Theory)13 IncompatibleDeviceException (com.android.tools.build.bundletool.model.exceptions.IncompatibleDeviceException)12 Variant (com.android.bundle.Commands.Variant)11 InvalidCommandException (com.android.tools.build.bundletool.model.exceptions.InvalidCommandException)11 ZipFile (java.util.zip.ZipFile)11 ApkSet (com.android.bundle.Commands.ApkSet)10 ImmutableList (com.google.common.collect.ImmutableList)9 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)9 ImmutableMap (com.google.common.collect.ImmutableMap)8 SystemEnvironmentProvider (com.android.tools.build.bundletool.model.utils.SystemEnvironmentProvider)7 PrintStream (java.io.PrintStream)7