Search in sources :

Example 1 with FakeAdbServer

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

Example 2 with FakeAdbServer

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");
}
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 3 with FakeAdbServer

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

Example 4 with FakeAdbServer

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");
}
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 5 with FakeAdbServer

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");
}
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)

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