Search in sources :

Example 16 with ZipPath

use of com.android.tools.build.bundletool.model.ZipPath 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 17 with ZipPath

use of com.android.tools.build.bundletool.model.ZipPath in project bundletool by google.

the class InstallApksCommandTest method deviceAbiIncompatible_throws.

@Test
public void deviceAbiIncompatible_throws() throws Exception {
    ZipPath apkL = ZipPath.create("splits/apkL.apk");
    ZipPath apkLx86 = ZipPath.create("splits/apkL-x86.apk");
    BuildApksResult tableOfContentsProto = BuildApksResult.newBuilder().setBundletool(Bundletool.newBuilder().setVersion(BundleToolVersion.getCurrentVersion().toString())).addVariant(createVariant(variantSdkTargeting(sdkVersionFrom(21)), createSplitApkSet("base", createMasterApkDescription(ApkTargeting.getDefaultInstance(), apkL), createApkDescription(apkAbiTargeting(X86, ImmutableSet.of()), apkLx86, /* isMasterSplit= */
    false)))).build();
    Path apksArchiveFile = createApksArchiveFile(tableOfContentsProto, tmpDir.resolve("bundle.apks"));
    DeviceSpec deviceSpec = mergeSpecs(sdkVersion(21), abis("arm64-v8a"), locales("en-US"), density(DensityAlias.HDPI));
    FakeDevice fakeDevice = FakeDevice.fromDeviceSpec(DEVICE_ID, DeviceState.ONLINE, deviceSpec);
    AdbServer adbServer = new FakeAdbServer(/* hasInitialDeviceList= */
    true, ImmutableList.of(fakeDevice));
    InstallApksCommand command = InstallApksCommand.builder().setApksArchivePath(apksArchiveFile).setAdbPath(adbPath).setAdbServer(adbServer).build();
    Throwable exception = assertThrows(IncompatibleDeviceException.class, command::execute);
    assertThat(exception).hasMessageThat().contains("The app doesn't support ABI architectures of the device. Device ABIs: [arm64-v8a], " + "app ABIs: [x86]");
}
Also used : Path(java.nio.file.Path) ZipPath(com.android.tools.build.bundletool.model.ZipPath) DeviceSpec(com.android.bundle.Devices.DeviceSpec) BuildApksResult(com.android.bundle.Commands.BuildApksResult) 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 18 with ZipPath

use of com.android.tools.build.bundletool.model.ZipPath in project bundletool by google.

the class InstallApksCommandTest method bundleWithDeviceTierTargeting_deviceTierSet_filtersByTier.

@Test
@Theory
public void bundleWithDeviceTierTargeting_deviceTierSet_filtersByTier(@FromDataPoints("apksInDirectory") boolean apksInDirectory) 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");
    ZipPath asset1MasterApk = ZipPath.create("asset1-master.apk");
    ZipPath asset1LowApk = ZipPath.create("asset1-tier_0.apk");
    ZipPath asset1HighApk = ZipPath.create("asset1-tier_1.apk");
    BuildApksResult tableOfContent = 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)))).addAssetSliceSet(AssetSliceSet.newBuilder().setAssetModuleMetadata(AssetModuleMetadata.newBuilder().setName("asset1").setDeliveryType(DeliveryType.ON_DEMAND)).addApkDescription(createMasterApkDescription(ApkTargeting.getDefaultInstance(), asset1MasterApk)).addApkDescription(splitApkDescription(apkDeviceTierTargeting(deviceTierTargeting(/* value= */
    0, /* alternatives= */
    ImmutableList.of(1))), asset1LowApk)).addApkDescription(splitApkDescription(apkDeviceTierTargeting(deviceTierTargeting(/* value= */
    1, /* alternatives= */
    ImmutableList.of(0))), asset1HighApk))).setLocalTestingInfo(LocalTestingInfo.newBuilder().setEnabled(true).setLocalTestingPath("local_testing")).addDefaultTargetingValue(DefaultTargetingValue.newBuilder().setDimension(Value.DEVICE_TIER).setDefaultValue("0")).build();
    Path apksFile = createApks(tableOfContent, apksInDirectory);
    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).setDeviceTier(1).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());
    // Base config splits and on-demand assets. Low tier splits are filtered out.
    assertThat(getFileNames(pushedFiles)).containsExactly(baseHighApk.toString(), asset1MasterApk.toString(), asset1HighApk.toString());
}
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) 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 19 with ZipPath

use of com.android.tools.build.bundletool.model.ZipPath in project bundletool by google.

the class InstallApksCommandTest method bundleWithDeviceTierTargeting_noDeviceTierSpecifiedNorDefault_usesZeroAsDefault.

@Test
public void bundleWithDeviceTierTargeting_noDeviceTierSpecifiedNorDefault_usesZeroAsDefault() 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)))).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. Tier 0 splits are returned, since it is the
    // default when unspecified.
    assertThat(getFileNames(installedApks)).containsExactly(baseMasterApk.toString(), baseLowApk.toString());
}
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) 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 20 with ZipPath

use of com.android.tools.build.bundletool.model.ZipPath 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());
}
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) 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)

Aggregations

ZipPath (com.android.tools.build.bundletool.model.ZipPath)194 Test (org.junit.Test)154 BuildApksResult (com.android.bundle.Commands.BuildApksResult)106 Path (java.nio.file.Path)55 DeviceSpec (com.android.bundle.Devices.DeviceSpec)44 InvalidBundleException (com.android.tools.build.bundletool.model.exceptions.InvalidBundleException)23 ImmutableSet (com.google.common.collect.ImmutableSet)23 ModuleEntry (com.android.tools.build.bundletool.model.ModuleEntry)19 Variant (com.android.bundle.Commands.Variant)16 ApksArchiveHelpers.createVariant (com.android.tools.build.bundletool.testing.ApksArchiveHelpers.createVariant)15 BundleModule (com.android.tools.build.bundletool.model.BundleModule)13 ImmutableList (com.google.common.collect.ImmutableList)12 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)11 ApksArchiveHelpers.standaloneVariant (com.android.tools.build.bundletool.testing.ApksArchiveHelpers.standaloneVariant)10 Theory (org.junit.experimental.theories.Theory)10 AdbServer (com.android.tools.build.bundletool.device.AdbServer)9 IOException (java.io.IOException)9 ModuleSplit (com.android.tools.build.bundletool.model.ModuleSplit)8 ImmutableSet.toImmutableSet (com.google.common.collect.ImmutableSet.toImmutableSet)8 UncheckedIOException (java.io.UncheckedIOException)8