Search in sources :

Example 26 with ZipPath

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

the class ApkMatcherTest method apkMatch_withModuleNameFiltering_splitApks_moduleWithDependency.

@Test
public void apkMatch_withModuleNameFiltering_splitApks_moduleWithDependency() {
    DeviceSpec device = deviceWithSdk(21);
    ZipPath baseApk = ZipPath.create("master-base.apk");
    ZipPath feature1Apk = ZipPath.create("master-feature1.apk");
    ZipPath feature2Apk = ZipPath.create("master-feature2.apk");
    BuildApksResult buildApksResult = buildApksResult(createVariant(VariantTargeting.getDefaultInstance(), splitApkSet(/* moduleName= */
    "base", splitApkDescription(ApkTargeting.getDefaultInstance(), baseApk)), splitApkSet(/* moduleName= */
    "feature1", DeliveryType.ON_DEMAND, /* moduleDependencies= */
    ImmutableList.of(), splitApkDescription(ApkTargeting.getDefaultInstance(), feature1Apk)), splitApkSet(/* moduleName= */
    "feature2", DeliveryType.ON_DEMAND, /* moduleDependencies= */
    ImmutableList.of("feature1"), splitApkDescription(ApkTargeting.getDefaultInstance(), feature2Apk))));
    // By default on-demand features are not installed.
    Optional<ImmutableSet<String>> allModules = Optional.empty();
    assertThat(createMatcher(device, allModules).getMatchingApks(buildApksResult)).containsExactly(baseMatchedApk(baseApk));
    Optional<ImmutableSet<String>> baseModuleOnly = Optional.of(ImmutableSet.of("base"));
    assertThat(createMatcher(device, baseModuleOnly).getMatchingApks(buildApksResult)).containsExactly(baseMatchedApk(baseApk));
    Optional<ImmutableSet<String>> feature2ModuleOnly = Optional.of(ImmutableSet.of("feature2"));
    assertThat(createMatcher(device, feature2ModuleOnly).getMatchingApks(buildApksResult)).containsExactly(baseMatchedApk(baseApk), matchedApk(feature1Apk, /* moduleName=*/
    "feature1", ON_DEMAND), matchedApk(feature2Apk, /* moduleName=*/
    "feature2", ON_DEMAND));
    Optional<ImmutableSet<String>> feature1ModuleOnly = Optional.of(ImmutableSet.of("feature1"));
    assertThat(createMatcher(device, feature1ModuleOnly).getMatchingApks(buildApksResult)).containsExactly(baseMatchedApk(baseApk), matchedApk(feature1Apk, /* moduleName=*/
    "feature1", ON_DEMAND));
}
Also used : DeviceSpec(com.android.bundle.Devices.DeviceSpec) ImmutableSet(com.google.common.collect.ImmutableSet) BuildApksResult(com.android.bundle.Commands.BuildApksResult) ZipPath(com.android.tools.build.bundletool.model.ZipPath) Test(org.junit.Test)

Example 27 with ZipPath

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

the class ApkMatcherTest method apkMatch_screenDensitySplit_noBetterAlternative.

@Test
public void apkMatch_screenDensitySplit_noBetterAlternative() {
    ZipPath apk = ZipPath.create("sample.apk");
    BuildApksResult buildApksResult = buildApksResult(oneApkSplitApkVariant(variantSdkTargeting(sdkVersionFrom(Versions.ANDROID_L_API_VERSION)), apkDensityTargeting(XXXHDPI, ImmutableSet.of(MDPI, HDPI)), apk));
    assertThat(new ApkMatcher(lDeviceWithDensity(XXHDPI)).getMatchingApks(buildApksResult)).containsExactly(baseMatchedApk(apk));
}
Also used : BuildApksResult(com.android.bundle.Commands.BuildApksResult) ZipPath(com.android.tools.build.bundletool.model.ZipPath) Test(org.junit.Test)

Example 28 with ZipPath

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

the class ApkMatcherTest method ensureDensityAndAbiSplitIsMatchedPerEachModule_split.

@Test
public void ensureDensityAndAbiSplitIsMatchedPerEachModule_split() {
    ZipPath baseMasterSplitApk = ZipPath.create("base-master.apk");
    ZipPath baseX86SplitApk = ZipPath.create("base-x86.apk");
    ZipPath baseMdpiSplitApk = ZipPath.create("base-mdpi.apk");
    ZipPath baseHdpiSplitApk = ZipPath.create("base-hdpi.apk");
    ZipPath screenMdpiApk = ZipPath.create("screen-mdpi.apk");
    BuildApksResult buildApksResult = buildApksResult(splitApkVariant(variantSdkTargeting(sdkVersionFrom(21), ImmutableSet.of(sdkVersionFrom(1))), splitApkSet(/* moduleName= */
    "base", splitApkDescription(ApkTargeting.getDefaultInstance(), baseMasterSplitApk), splitApkDescription(apkAbiTargeting(X86, ImmutableSet.of(X86_64)), baseX86SplitApk), splitApkDescription(apkDensityTargeting(MDPI, ImmutableSet.of(HDPI, XHDPI)), baseMdpiSplitApk), splitApkDescription(apkDensityTargeting(HDPI, ImmutableSet.of(MDPI, XHDPI)), baseHdpiSplitApk)), splitApkSet(/* moduleName= */
    "screen", splitApkDescription(apkDensityTargeting(MDPI, ImmutableSet.of(HDPI)), screenMdpiApk))));
    Optional<ImmutableSet<String>> allModules = Optional.of(ImmutableSet.of("base", "screen"));
    assertThat(createSafeMatcher(mergeSpecs(density(MDPI), abis("x86")), allModules).getMatchingApks(buildApksResult)).containsExactly(matchedApk(baseMasterSplitApk, "base", INSTALL_TIME), matchedApk(baseX86SplitApk, "base", INSTALL_TIME), matchedApk(baseMdpiSplitApk, "base", INSTALL_TIME), matchedApk(screenMdpiApk, "screen", INSTALL_TIME));
    IncompatibleDeviceException baseException = assertThrows(IncompatibleDeviceException.class, () -> createSafeMatcher(mergeSpecs(density(MDPI), abis("x86_64")), allModules).getMatchingApks(buildApksResult));
    assertThat(baseException).hasMessageThat().isEqualTo("Missing APKs for [ABI] dimensions in the module 'base' for the provided device.");
    IncompatibleDeviceException screenException = assertThrows(IncompatibleDeviceException.class, () -> createSafeMatcher(mergeSpecs(density(HDPI), abis("x86")), allModules).getMatchingApks(buildApksResult));
    assertThat(screenException).hasMessageThat().isEqualTo("Missing APKs for [SCREEN_DENSITY] dimensions in the module 'screen' for the provided" + " device.");
    IncompatibleDeviceException multipleDimensionsException = assertThrows(IncompatibleDeviceException.class, () -> createSafeMatcher(mergeSpecs(density(XHDPI), abis("x86_64")), allModules).getMatchingApks(buildApksResult));
    assertThat(multipleDimensionsException).hasMessageThat().isEqualTo("Missing APKs for [ABI, SCREEN_DENSITY] dimensions in the module 'base' for the" + " provided device.");
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) BuildApksResult(com.android.bundle.Commands.BuildApksResult) ZipPath(com.android.tools.build.bundletool.model.ZipPath) IncompatibleDeviceException(com.android.tools.build.bundletool.model.exceptions.IncompatibleDeviceException) Test(org.junit.Test)

Example 29 with ZipPath

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

the class ApkMatcherTest method apkNoMatch_deviceDoesntMatchVariantValue_bothBetterAndNoBetterAlternatives.

@Test
public void apkNoMatch_deviceDoesntMatchVariantValue_bothBetterAndNoBetterAlternatives() {
    ZipPath apk = ZipPath.create("sample.apk");
    BuildApksResult buildApksResult = buildApksResult(oneApkSplitApkVariant(variantSdkTargeting(sdkVersionFrom(21), ImmutableSet.of(sdkVersionFrom(1), sdkVersionFrom(23))), ApkTargeting.getDefaultInstance(), apk));
    assertThat(new ApkMatcher(deviceWithSdk(19)).getMatchingApks(buildApksResult)).isEmpty();
}
Also used : BuildApksResult(com.android.bundle.Commands.BuildApksResult) ZipPath(com.android.tools.build.bundletool.model.ZipPath) Test(org.junit.Test)

Example 30 with ZipPath

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

the class ApkMatcherTest method apkMatch_withModuleNameFiltering_instantApks_checksModuleName_isEmpty.

@Test
public void apkMatch_withModuleNameFiltering_instantApks_checksModuleName_isEmpty() {
    DeviceSpec device = deviceWithSdk(21);
    ZipPath apk = ZipPath.create("master-de-fr.apk");
    BuildApksResult buildApksResult = buildApksResult(createVariant(VariantTargeting.getDefaultInstance(), splitApkSet(/* moduleName= */
    "base", splitApkDescription(ApkTargeting.getDefaultInstance(), apk))));
    Optional<ImmutableSet<String>> allModules = Optional.empty();
    assertThat(createInstantMatcher(device, allModules).getMatchingApks(buildApksResult)).isEmpty();
    Optional<ImmutableSet<String>> baseModuleOnly = Optional.of(ImmutableSet.of("base"));
    assertThat(createInstantMatcher(device, baseModuleOnly).getMatchingApks(buildApksResult)).isEmpty();
    Optional<ImmutableSet<String>> featureModuleOnly = Optional.of(ImmutableSet.of("feature"));
    // No matching instant variant
    assertThat(createInstantMatcher(device, featureModuleOnly).getMatchingApks(buildApksResult)).isEmpty();
}
Also used : DeviceSpec(com.android.bundle.Devices.DeviceSpec) ImmutableSet(com.google.common.collect.ImmutableSet) BuildApksResult(com.android.bundle.Commands.BuildApksResult) ZipPath(com.android.tools.build.bundletool.model.ZipPath) 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