Search in sources :

Example 51 with ZipPath

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

the class ApkMatcherTest method apkMatch_screenDensitySplit.

// Density splits.
@Test
public void apkMatch_screenDensitySplit() {
    ZipPath apk = ZipPath.create("sample.apk");
    BuildApksResult buildApksResult = buildApksResult(oneApkSplitApkVariant(variantSdkTargeting(sdkVersionFrom(Versions.ANDROID_L_API_VERSION)), apkDensityTargeting(HDPI), apk));
    assertThat(new ApkMatcher(lDeviceWithDensity(HDPI)).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 52 with ZipPath

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

the class ApkMatcherTest method apkMatch_withModuleTypeFiltering_splitApks_installTimeModules.

@Test
public void apkMatch_withModuleTypeFiltering_splitApks_installTimeModules() {
    DeviceSpec device = deviceWithSdk(21);
    ZipPath baseApk = ZipPath.create("master-base.apk");
    ZipPath onDemandFeatureApk = ZipPath.create("master-feature1.apk");
    ZipPath installTimeFeatureApk = ZipPath.create("master-feature2.apk");
    ZipPath fastFollowFeatureApk = ZipPath.create("master-feature3.apk");
    BuildApksResult buildApksResult = buildApksResult(createVariant(VariantTargeting.getDefaultInstance(), splitApkSet(/* moduleName= */
    "base", splitApkDescription(ApkTargeting.getDefaultInstance(), baseApk)), splitApkSet(/* moduleName= */
    "onDemandFeature", DeliveryType.ON_DEMAND, /* moduleDependencies= */
    ImmutableList.of(), splitApkDescription(ApkTargeting.getDefaultInstance(), onDemandFeatureApk)), splitApkSet(/* moduleName= */
    "installTimeFeature", INSTALL_TIME, /* moduleDependencies= */
    ImmutableList.of(), splitApkDescription(ApkTargeting.getDefaultInstance(), installTimeFeatureApk)), splitApkSet(/* moduleName= */
    "fastFollowFeature", /* deliveryType= */
    DeliveryType.FAST_FOLLOW, /* moduleDependencies= */
    ImmutableList.of(), splitApkDescription(ApkTargeting.getDefaultInstance(), fastFollowFeatureApk))));
    // By default only install-time module are matched.
    Optional<ImmutableSet<String>> allModules = Optional.empty();
    assertThat(createMatcher(device, allModules).getMatchingApks(buildApksResult)).containsExactly(matchedApk(baseApk, /* moduleName=*/
    "base", INSTALL_TIME), matchedApk(installTimeFeatureApk, /* moduleName=*/
    "installTimeFeature", INSTALL_TIME));
    Optional<ImmutableSet<String>> baseModuleOnly = Optional.of(ImmutableSet.of("base"));
    assertThat(createMatcher(device, baseModuleOnly).getMatchingApks(buildApksResult)).containsExactly(matchedApk(baseApk, /* moduleName=*/
    "base", INSTALL_TIME), matchedApk(installTimeFeatureApk, /* moduleName=*/
    "installTimeFeature", INSTALL_TIME));
    Optional<ImmutableSet<String>> installTimeModuleOnly = Optional.of(ImmutableSet.of("installTimeFeature"));
    assertThat(createMatcher(device, installTimeModuleOnly).getMatchingApks(buildApksResult)).containsExactly(matchedApk(baseApk, /* moduleName=*/
    "base", INSTALL_TIME), matchedApk(installTimeFeatureApk, /* moduleName=*/
    "installTimeFeature", INSTALL_TIME));
    Optional<ImmutableSet<String>> onDemandModuleOnly = Optional.of(ImmutableSet.of("onDemandFeature"));
    assertThat(createMatcher(device, onDemandModuleOnly).getMatchingApks(buildApksResult)).containsExactly(matchedApk(baseApk, /* moduleName=*/
    "base", INSTALL_TIME), matchedApk(onDemandFeatureApk, /* moduleName=*/
    "onDemandFeature", ON_DEMAND), matchedApk(installTimeFeatureApk, /* moduleName=*/
    "installTimeFeature", INSTALL_TIME));
    Optional<ImmutableSet<String>> fastFollowModuleOnly = Optional.of(ImmutableSet.of("fastFollowFeature"));
    assertThat(createMatcher(device, fastFollowModuleOnly).getMatchingApks(buildApksResult)).containsExactly(matchedApk(baseApk, /* moduleName=*/
    "base", INSTALL_TIME), matchedApk(fastFollowFeatureApk, /* moduleName=*/
    "fastFollowFeature", FAST_FOLLOW), matchedApk(installTimeFeatureApk, /* moduleName=*/
    "installTimeFeature", INSTALL_TIME));
}
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 53 with ZipPath

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

the class ApkMatcherTest method apkNoMatch_deviceMatchesVariantDefaultValue_betterAlternative.

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

Example 54 with ZipPath

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

the class ApkMatcherTest method apkMatch_languageSplit_alternatives.

@Test
public void apkMatch_languageSplit_alternatives() {
    ZipPath enApk = ZipPath.create("master-en.apk");
    ZipPath frApk = ZipPath.create("master-fr.apk");
    BuildApksResult buildApksResult = buildApksResult(createVariant(variantSdkTargeting(sdkVersionFrom(Versions.ANDROID_L_API_VERSION)), splitApkSet("base", splitApkDescription(apkLanguageTargeting("en"), enApk)), splitApkSet("base", splitApkDescription(apkLanguageTargeting("fr"), frApk))));
    // Even though there is a 'better alternative' from the point of view of the phone settings
    // we pick all languages that match the device. The list of locales on device is ordered based
    // on preference.
    assertThat(new ApkMatcher(lDeviceWithLocales("en-GB", "fr-FR")).getMatchingApks(buildApksResult)).containsExactly(baseMatchedApk(enApk), baseMatchedApk(frApk));
}
Also used : BuildApksResult(com.android.bundle.Commands.BuildApksResult) ZipPath(com.android.tools.build.bundletool.model.ZipPath) Test(org.junit.Test)

Example 55 with ZipPath

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

the class VariantMatcherTest method getAllMatchingVariants_apexVariants_noMatch_throws.

@Test
public void getAllMatchingVariants_apexVariants_noMatch_throws() {
    ZipPath x86Apk = ZipPath.create("standalone-x86.apk");
    ZipPath x64X86Apk = ZipPath.create("standalone-x86_64.x86.apk");
    ImmutableSet<ImmutableSet<AbiAlias>> x86Set = ImmutableSet.of(ImmutableSet.of(X86));
    ImmutableSet<ImmutableSet<AbiAlias>> x64X86Set = ImmutableSet.of(ImmutableSet.of(X86_64, X86));
    MultiAbiTargeting x86Targeting = multiAbiTargeting(x86Set, x64X86Set);
    MultiAbiTargeting x64X86Targeting = multiAbiTargeting(x64X86Set, x86Set);
    Variant x86Variant = multiAbiTargetingApexVariant(x86Targeting, x86Apk);
    Variant x64X86Variant = multiAbiTargetingApexVariant(x64X86Targeting, x64X86Apk);
    BuildApksResult buildApksResult = BuildApksResult.newBuilder().addAllVariant(ImmutableList.of(x86Variant, x64X86Variant)).build();
    IncompatibleDeviceException e = assertThrows(IncompatibleDeviceException.class, () -> new VariantMatcher(abis("x86_64", "armeabi-v7a")).getAllMatchingVariants(buildApksResult));
    assertThat(e).hasMessageThat().contains("No set of ABI architectures that the app supports is contained in the ABI " + "architecture set of the device");
}
Also used : ApksArchiveHelpers.createVariant(com.android.tools.build.bundletool.testing.ApksArchiveHelpers.createVariant) Variant(com.android.bundle.Commands.Variant) ApksArchiveHelpers.multiAbiTargetingApexVariant(com.android.tools.build.bundletool.testing.ApksArchiveHelpers.multiAbiTargetingApexVariant) ApksArchiveHelpers.standaloneVariant(com.android.tools.build.bundletool.testing.ApksArchiveHelpers.standaloneVariant) 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) MultiAbiTargeting(com.android.bundle.Targeting.MultiAbiTargeting) 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