Search in sources :

Example 6 with AdbServer

use of com.android.tools.build.bundletool.device.AdbServer in project bundletool by google.

the class InstallApksCommandTest method deviceSdkIncompatible_throws.

@Test
public void deviceSdkIncompatible_throws() throws Exception {
    Path apksFile = createApksArchiveFile(createLPlusTableOfContent(ZipPath.create("base-master.apk")), tmpDir.resolve("bundle.apks"));
    FakeDevice fakeDevice = FakeDevice.fromDeviceSpec(DEVICE_ID, DeviceState.ONLINE, mergeSpecs(sdkVersion(19), abis("arm64_v8a"), locales("en-US"), density(DensityAlias.HDPI)));
    AdbServer adbServer = new FakeAdbServer(/* hasInitialDeviceList= */
    true, ImmutableList.of(fakeDevice));
    InstallApksCommand command = InstallApksCommand.builder().setApksArchivePath(apksFile).setAdbPath(adbPath).setAdbServer(adbServer).build();
    Throwable exception = assertThrows(IncompatibleDeviceException.class, command::execute);
    assertThat(exception).hasMessageThat().contains("The app doesn't support SDK version of the device: (19).");
}
Also used : Path(java.nio.file.Path) ZipPath(com.android.tools.build.bundletool.model.ZipPath) 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)

Example 7 with AdbServer

use of com.android.tools.build.bundletool.device.AdbServer in project bundletool by google.

the class InstallApksCommandTest method localTestingMode_defaultModules.

@Test
@Theory
public void localTestingMode_defaultModules(@FromDataPoints("apksInDirectory") boolean apksInDirectory) throws Exception {
    String installTimeFeature = "installtime_feature";
    String onDemandFeature = "ondemand_feature";
    String installTimeAsset = "installtime_asset";
    String onDemandAsset = "ondemand_asset";
    ZipPath baseApk = ZipPath.create("base-master.apk");
    ZipPath baseEnApk = ZipPath.create("base-en.apk");
    ZipPath installTimeFeatureMasterApk = ZipPath.create(installTimeFeature + "-master.apk");
    ZipPath installTimeFeatureEnApk = ZipPath.create(installTimeFeature + "-en.apk");
    ZipPath installTimeFeaturePlApk = ZipPath.create(installTimeFeature + "-pl.apk");
    ZipPath onDemandFeatureMasterApk = ZipPath.create(onDemandFeature + "-master.apk");
    ZipPath installTimeAssetMasterApk = ZipPath.create(installTimeAsset + "-master.apk");
    ZipPath installTimeAssetEnApk = ZipPath.create(installTimeAsset + "-en.apk");
    ZipPath onDemandAssetMasterApk = ZipPath.create(onDemandAsset + "-master.apk");
    BuildApksResult tableOfContent = BuildApksResult.newBuilder().setPackageName(PKG_NAME).setBundletool(Bundletool.newBuilder().setVersion(BundleToolVersion.getCurrentVersion().toString())).addVariant(createVariant(VariantTargeting.getDefaultInstance(), createSplitApkSet("base", createMasterApkDescription(ApkTargeting.getDefaultInstance(), baseApk), createApkDescription(apkLanguageTargeting("en"), baseEnApk, /* isMasterSplit= */
    false)), createSplitApkSet(installTimeFeature, createMasterApkDescription(ApkTargeting.getDefaultInstance(), installTimeFeatureMasterApk), createApkDescription(apkLanguageTargeting("en"), installTimeFeatureEnApk, /* isMasterSplit= */
    false), createApkDescription(apkLanguageTargeting("pl"), installTimeFeaturePlApk, /* isMasterSplit= */
    false)), createSplitApkSet(onDemandFeature, DeliveryType.ON_DEMAND, /* moduleDependencies= */
    ImmutableList.of(), createMasterApkDescription(ApkTargeting.getDefaultInstance(), onDemandFeatureMasterApk)))).addAssetSliceSet(AssetSliceSet.newBuilder().setAssetModuleMetadata(AssetModuleMetadata.newBuilder().setName(installTimeAsset).setDeliveryType(DeliveryType.INSTALL_TIME)).addApkDescription(splitApkDescription(ApkTargeting.getDefaultInstance(), installTimeAssetMasterApk)).addApkDescription(splitApkDescription(apkLanguageTargeting("en"), installTimeAssetEnApk))).addAssetSliceSet(AssetSliceSet.newBuilder().setAssetModuleMetadata(AssetModuleMetadata.newBuilder().setName(onDemandAsset).setDeliveryType(DeliveryType.ON_DEMAND)).addApkDescription(splitApkDescription(ApkTargeting.getDefaultInstance(), onDemandAssetMasterApk))).setLocalTestingInfo(LocalTestingInfo.newBuilder().setEnabled(true).setLocalTestingPath("local_testing").build()).build();
    Path apksFile = createApks(tableOfContent, apksInDirectory);
    Duration timeout = Duration.ofMinutes(5);
    List<Path> installedApks = new ArrayList<>();
    List<Path> pushedFiles = new ArrayList<>();
    List<String> clearedPathes = new ArrayList<>();
    FakeDevice fakeDevice = FakeDevice.fromDeviceSpec(DEVICE_ID, DeviceState.ONLINE, lDeviceWithLocales("en-US"));
    AdbServer adbServer = new FakeAdbServer(/* hasInitialDeviceList= */
    true, ImmutableList.of(fakeDevice));
    fakeDevice.setInstallApksSideEffect((apks, installOptions) -> {
        assertThat(installOptions.getTimeout()).isEqualTo(timeout);
        installedApks.addAll(apks);
    });
    fakeDevice.setPushSideEffect((files, pushOptions) -> {
        assertThat(pushOptions.getTimeout()).isEqualTo(timeout);
        pushedFiles.addAll(files);
    });
    fakeDevice.setRemoveRemotePathSideEffect((remotePath, runAs, removeTimeout) -> {
        assertThat(removeTimeout).isEqualTo(timeout);
        assertThat(runAs).hasValue(PKG_NAME);
        clearedPathes.add(remotePath);
    });
    InstallApksCommand.builder().setApksArchivePath(apksFile).setAdbPath(adbPath).setAdbServer(adbServer).setTimeout(timeout).build().execute();
    // Base, install-time features and install-time assets.
    assertThat(getFileNames(installedApks)).containsExactly(baseApk.toString(), baseEnApk.toString(), installTimeFeatureMasterApk.toString(), installTimeFeatureEnApk.toString(), installTimeAssetMasterApk.toString(), installTimeAssetEnApk.toString());
    // Base config splits, install-time and on-demand features and on-demand assets. All languages.
    assertThat(getFileNames(pushedFiles)).containsExactly(baseEnApk.toString(), installTimeFeatureMasterApk.toString(), installTimeFeatureEnApk.toString(), installTimeFeaturePlApk.toString(), onDemandFeatureMasterApk.toString(), onDemandAssetMasterApk.toString());
    assertThat(clearedPathes).containsExactly(LocalTestingPathResolver.getLocalTestingWorkingDir(PKG_NAME));
}
Also used : Path(java.nio.file.Path) ZipPath(com.android.tools.build.bundletool.model.ZipPath) BuildApksResult(com.android.bundle.Commands.BuildApksResult) ArrayList(java.util.ArrayList) Duration(java.time.Duration) ZipPath(com.android.tools.build.bundletool.model.ZipPath) 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) Theory(org.junit.experimental.theories.Theory)

Example 8 with AdbServer

use of com.android.tools.build.bundletool.device.AdbServer in project bundletool by google.

the class InstallApksCommandTest method noLocalTesting_additionalLocalTestingFiles_throws.

@Test
public void noLocalTesting_additionalLocalTestingFiles_throws() throws Exception {
    Path additionalXml = tmpDir.resolve("additional.xml");
    Files.write(additionalXml, new byte[0]);
    AdbServer adbServer = new FakeAdbServer(/* hasInitialDeviceList= */
    true, ImmutableList.of(FakeDevice.fromDeviceSpec(DEVICE_ID, DeviceState.ONLINE, lDeviceWithLocales("en-US"))));
    InstallApksCommand command = InstallApksCommand.builder().setApksArchivePath(simpleApksPath).setAdbPath(adbPath).setAdbServer(adbServer).setAdditionalLocalTestingFiles(ImmutableList.of(additionalXml)).build();
    IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, command::execute);
    assertThat(exception).hasMessageThat().contains("'additional-local-testing-files' flag is only supported for APKs built in local" + " testing mode.");
}
Also used : Path(java.nio.file.Path) ZipPath(com.android.tools.build.bundletool.model.ZipPath) 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)

Example 9 with AdbServer

use of com.android.tools.build.bundletool.device.AdbServer in project bundletool by google.

the class InstallApksCommandTest method moduleDependencies_installDependency.

@Test
@Theory
public void moduleDependencies_installDependency(@FromDataPoints("apksInDirectory") boolean apksInDirectory) throws Exception {
    BuildApksResult tableOfContent = BuildApksResult.newBuilder().setBundletool(Bundletool.newBuilder().setVersion(BundleToolVersion.getCurrentVersion().toString())).addVariant(createVariant(VariantTargeting.getDefaultInstance(), createSplitApkSet(/* moduleName= */
    "base", createMasterApkDescription(ApkTargeting.getDefaultInstance(), ZipPath.create("base-master.apk"))), createSplitApkSet(/* moduleName= */
    "feature1", DeliveryType.ON_DEMAND, /* moduleDependencies= */
    ImmutableList.of(), createMasterApkDescription(ApkTargeting.getDefaultInstance(), ZipPath.create("feature1-master.apk"))), createSplitApkSet(/* moduleName= */
    "feature2", DeliveryType.ON_DEMAND, /* moduleDependencies= */
    ImmutableList.of("feature1"), createMasterApkDescription(ApkTargeting.getDefaultInstance(), ZipPath.create("feature2-master.apk"))), createSplitApkSet(/* moduleName= */
    "feature3", DeliveryType.ON_DEMAND, /* moduleDependencies= */
    ImmutableList.of("feature2"), createMasterApkDescription(ApkTargeting.getDefaultInstance(), ZipPath.create("feature3-master.apk"))))).build();
    Path apksFile = createApks(tableOfContent, apksInDirectory);
    List<Path> installedApks = new ArrayList<>();
    FakeDevice fakeDevice = FakeDevice.fromDeviceSpec(DEVICE_ID, DeviceState.ONLINE, lDeviceWithLocales("en-US"));
    AdbServer adbServer = new FakeAdbServer(/* hasInitialDeviceList= */
    true, ImmutableList.of(fakeDevice));
    fakeDevice.setInstallApksSideEffect((apks, installOptions) -> installedApks.addAll(apks));
    InstallApksCommand.builder().setApksArchivePath(apksFile).setAdbPath(adbPath).setAdbServer(adbServer).setModules(ImmutableSet.of("feature2")).build().execute();
    assertThat(getFileNames(installedApks)).containsExactly("base-master.apk", "feature1-master.apk", "feature2-master.apk");
}
Also used : Path(java.nio.file.Path) ZipPath(com.android.tools.build.bundletool.model.ZipPath) BuildApksResult(com.android.bundle.Commands.BuildApksResult) ArrayList(java.util.ArrayList) 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) Theory(org.junit.experimental.theories.Theory)

Example 10 with AdbServer

use of com.android.tools.build.bundletool.device.AdbServer in project bundletool by google.

the class InstallApksCommandTest method missingDeviceWithId.

@Test
public void missingDeviceWithId() throws Exception {
    AdbServer adbServer = new FakeAdbServer(/* hasInitialDeviceList= */
    true, ImmutableList.of(FakeDevice.fromDeviceSpec(DEVICE_ID, DeviceState.ONLINE, lDeviceWithLocales("en-US"))));
    InstallApksCommand command = InstallApksCommand.builder().setApksArchivePath(simpleApksPath).setAdbPath(adbPath).setAdbServer(adbServer).setDeviceId("doesnt-exist").build();
    Throwable exception = assertThrows(CommandExecutionException.class, () -> command.execute());
    assertThat(exception).hasMessageThat().contains("Unable to find the requested device.");
}
Also used : 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

AdbServer (com.android.tools.build.bundletool.device.AdbServer)25 FakeAdbServer (com.android.tools.build.bundletool.testing.FakeAdbServer)20 Test (org.junit.Test)20 Path (java.nio.file.Path)19 ZipPath (com.android.tools.build.bundletool.model.ZipPath)17 FakeDevice (com.android.tools.build.bundletool.testing.FakeDevice)17 BuildApksResult (com.android.bundle.Commands.BuildApksResult)13 ArrayList (java.util.ArrayList)10 DeviceSpec (com.android.bundle.Devices.DeviceSpec)9 Theory (org.junit.experimental.theories.Theory)9 DeviceAnalyzer (com.android.tools.build.bundletool.device.DeviceAnalyzer)4 ParsedFlags (com.android.tools.build.bundletool.flags.ParsedFlags)2 TempDirectory (com.android.tools.build.bundletool.io.TempDirectory)2 BundleConfig (com.android.bundle.Config.BundleConfig)1 Aapt2Command (com.android.tools.build.bundletool.androidtools.Aapt2Command)1 AdbCommand (com.android.tools.build.bundletool.androidtools.AdbCommand)1 ApkBuildMode (com.android.tools.build.bundletool.commands.BuildApksCommand.ApkBuildMode)1 CommandDescription (com.android.tools.build.bundletool.commands.CommandHelp.CommandDescription)1 FlagDescription (com.android.tools.build.bundletool.commands.CommandHelp.FlagDescription)1 ANDROID_SERIAL_VARIABLE (com.android.tools.build.bundletool.commands.CommandUtils.ANDROID_SERIAL_VARIABLE)1