use of com.android.tools.build.bundletool.device.AdbServer in project bundletool by google.
the class InstallApksCommandTest method bundleWithDeviceTierTargeting_noDeviceTierSpecified_usesDefaultValue.
@Test
public void bundleWithDeviceTierTargeting_noDeviceTierSpecified_usesDefaultValue() throws Exception {
ZipPath baseMasterApk = ZipPath.create("base-master.apk");
ZipPath baseLowApk = ZipPath.create("base-tier_0.apk");
ZipPath baseHighApk = ZipPath.create("base-tier_1.apk");
BuildApksResult buildApksResult = BuildApksResult.newBuilder().setPackageName(PKG_NAME).setBundletool(Bundletool.newBuilder().setVersion(BundleToolVersion.getCurrentVersion().toString())).addVariant(createVariant(variantSdkTargeting(sdkVersionFrom(21), ImmutableSet.of(SdkVersion.getDefaultInstance())), createSplitApkSet("base", createMasterApkDescription(ApkTargeting.getDefaultInstance(), baseMasterApk), splitApkDescription(apkDeviceTierTargeting(deviceTierTargeting(/* value= */
0, /* alternatives= */
ImmutableList.of(1))), baseLowApk), splitApkDescription(apkDeviceTierTargeting(deviceTierTargeting(/* value= */
1, /* alternatives= */
ImmutableList.of(0))), baseHighApk)))).addDefaultTargetingValue(DefaultTargetingValue.newBuilder().setDimension(Value.DEVICE_TIER).setDefaultValue("1")).build();
Path apksFile = createApksArchiveFile(buildApksResult, tmpDir.resolve("bundle.apks"));
List<Path> installedApks = new ArrayList<>();
FakeDevice fakeDevice = FakeDevice.fromDeviceSpec(DEVICE_ID, DeviceState.ONLINE, lDeviceWithLocales("en-US"));
fakeDevice.setInstallApksSideEffect((apks, installOptions) -> installedApks.addAll(apks));
AdbServer adbServer = new FakeAdbServer(/* hasInitialDeviceList= */
true, ImmutableList.of(fakeDevice));
InstallApksCommand.builder().setApksArchivePath(apksFile).setAdbPath(adbPath).setAdbServer(adbServer).build().execute();
// Base only, the on demand asset is not installed. Low tier splits are filtered out.
assertThat(getFileNames(installedApks)).containsExactly(baseMasterApk.toString(), baseHighApk.toString());
}
use of com.android.tools.build.bundletool.device.AdbServer in project bundletool by google.
the class InstallApksCommandTest method noDeviceId_moreThanOneDeviceConnected.
@Test
public void noDeviceId_moreThanOneDeviceConnected() throws Exception {
AdbServer adbServer = new FakeAdbServer(/* hasInitialDeviceList= */
true, ImmutableList.of(FakeDevice.fromDeviceSpec(DEVICE_ID, DeviceState.ONLINE, lDeviceWithLocales("en-US")), FakeDevice.fromDeviceSpec("id2", DeviceState.ONLINE, lDeviceWithLocales("en-US", "en-GB"))));
InstallApksCommand command = InstallApksCommand.builder().setApksArchivePath(simpleApksPath).setAdbPath(adbPath).setAdbServer(adbServer).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.device.AdbServer in project bundletool by google.
the class InstallApksCommandTest method installAssetModules.
@Test
@Theory
public void installAssetModules(@FromDataPoints("apksInDirectory") boolean apksInDirectory) throws Exception {
String installTimeModule1 = "installtime_assetmodule1";
String installTimeModule2 = "installtime_assetmodule2";
String onDemandModule = "ondemand_assetmodule";
ZipPath installTimeMasterApk1 = ZipPath.create(installTimeModule1 + "-master.apk");
ZipPath installTimeEnApk1 = ZipPath.create(installTimeModule1 + "-en.apk");
ZipPath installTimeMasterApk2 = ZipPath.create(installTimeModule2 + "-master.apk");
ZipPath installTimeEnApk2 = ZipPath.create(installTimeModule2 + "-en.apk");
ZipPath onDemandMasterApk = ZipPath.create(onDemandModule + "-master.apk");
ZipPath baseApk = ZipPath.create("base-master.apk");
BuildApksResult tableOfContent = BuildApksResult.newBuilder().setBundletool(Bundletool.newBuilder().setVersion(BundleToolVersion.getCurrentVersion().toString())).addVariant(createVariant(VariantTargeting.getDefaultInstance(), createSplitApkSet("base", createMasterApkDescription(ApkTargeting.getDefaultInstance(), baseApk)))).addAssetSliceSet(AssetSliceSet.newBuilder().setAssetModuleMetadata(AssetModuleMetadata.newBuilder().setName(installTimeModule1).setDeliveryType(DeliveryType.INSTALL_TIME)).addApkDescription(splitApkDescription(ApkTargeting.getDefaultInstance(), installTimeMasterApk1)).addApkDescription(splitApkDescription(apkLanguageTargeting("en"), installTimeEnApk1))).addAssetSliceSet(AssetSliceSet.newBuilder().setAssetModuleMetadata(AssetModuleMetadata.newBuilder().setName(installTimeModule2).setDeliveryType(DeliveryType.INSTALL_TIME)).addApkDescription(splitApkDescription(ApkTargeting.getDefaultInstance(), installTimeMasterApk2)).addApkDescription(splitApkDescription(apkLanguageTargeting("en"), installTimeEnApk2))).addAssetSliceSet(AssetSliceSet.newBuilder().setAssetModuleMetadata(AssetModuleMetadata.newBuilder().setName(onDemandModule).setDeliveryType(DeliveryType.ON_DEMAND)).addApkDescription(splitApkDescription(ApkTargeting.getDefaultInstance(), onDemandMasterApk))).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(installTimeModule1)).build().execute();
assertThat(getFileNames(installedApks)).containsExactly(baseApk.toString(), installTimeMasterApk1.toString(), installTimeEnApk1.toString());
}
use of com.android.tools.build.bundletool.device.AdbServer in project bundletool by google.
the class InstallApksCommandTest method installsOnlySpecifiedModules.
@Test
@Theory
public void installsOnlySpecifiedModules(@FromDataPoints("apksInDirectory") boolean apksInDirectory) throws Exception {
BuildApksResult tableOfContent = BuildApksResult.newBuilder().setBundletool(Bundletool.newBuilder().setVersion(BundleToolVersion.getCurrentVersion().toString())).addVariant(createVariant(VariantTargeting.getDefaultInstance(), createSplitApkSet("base", createMasterApkDescription(ApkTargeting.getDefaultInstance(), ZipPath.create("base-master.apk"))), createSplitApkSet("feature1", createMasterApkDescription(ApkTargeting.getDefaultInstance(), ZipPath.create("feature1-master.apk"))), createSplitApkSet("feature2", createMasterApkDescription(ApkTargeting.getDefaultInstance(), ZipPath.create("feature2-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("base", "feature2")).build().execute();
assertThat(getFileNames(installedApks)).containsExactly("base-master.apk", "feature1-master.apk", "feature2-master.apk");
}
use of com.android.tools.build.bundletool.device.AdbServer in project bundletool by google.
the class InstallApksCommandTest method localTestingMode_additionalLocalTestingFiles.
@Test
public void localTestingMode_additionalLocalTestingFiles() throws Exception {
ZipPath baseApk = ZipPath.create("base-master.apk");
ZipPath baseEnApk = ZipPath.create("base-en.apk");
ZipPath onDemandFeatureMasterApk = ZipPath.create("ondemand_feature-master.apk");
Path additionalXml = tmpDir.resolve("additional.xml");
Files.write(additionalXml, new byte[0]);
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("ondemand_feature", DeliveryType.ON_DEMAND, /* moduleDependencies= */
ImmutableList.of(), createMasterApkDescription(ApkTargeting.getDefaultInstance(), onDemandFeatureMasterApk)))).setLocalTestingInfo(LocalTestingInfo.newBuilder().setEnabled(true).setLocalTestingPath("local_testing").build()).build();
Path apksFile = createApks(tableOfContent, /* apksInDirectory= */
false);
List<Path> installedApks = new ArrayList<>();
List<Path> pushedFiles = 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));
fakeDevice.setPushSideEffect((files, installOptions) -> pushedFiles.addAll(files));
InstallApksCommand.builder().setApksArchivePath(apksFile).setAdbPath(adbPath).setAdbServer(adbServer).setAdditionalLocalTestingFiles(ImmutableList.of(additionalXml)).build().execute();
// Base, install-time and on-demand features and install-time assets.
assertThat(getFileNames(installedApks)).containsExactly(baseApk.toString(), baseEnApk.toString());
// Base config splits, install-time and on-demand features and on-demand assets. All languages.
assertThat(getFileNames(pushedFiles)).containsExactly(baseEnApk.toString(), onDemandFeatureMasterApk.toString(), additionalXml.getFileName().toString());
}
Aggregations