Search in sources :

Example 86 with BuildApksResult

use of com.android.bundle.Commands.BuildApksResult 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 87 with BuildApksResult

use of com.android.bundle.Commands.BuildApksResult 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 88 with BuildApksResult

use of com.android.bundle.Commands.BuildApksResult 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 89 with BuildApksResult

use of com.android.bundle.Commands.BuildApksResult 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)

Example 90 with BuildApksResult

use of com.android.bundle.Commands.BuildApksResult in project bundletool by google.

the class VariantMatcherTest method getAllMatchingVariants_apexVariants_fullDeviceSpec.

@Test
public void getAllMatchingVariants_apexVariants_fullDeviceSpec() {
    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();
    assertThat(new VariantMatcher(abis("x86")).getAllMatchingVariants(buildApksResult)).containsExactly(x86Variant);
    assertThat(new VariantMatcher(abis("x86_64", "x86")).getAllMatchingVariants(buildApksResult)).containsExactly(x64X86Variant);
    assertThat(new VariantMatcher(abis("x86_64", "x86", "armeabi-v7a")).getAllMatchingVariants(buildApksResult)).containsExactly(x64X86Variant);
    // Other device specs don't affect the matching variant.
    assertThat(new VariantMatcher(mergeSpecs(abis("x86"), density(HDPI))).getAllMatchingVariants(buildApksResult)).containsExactly(x86Variant);
}
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) MultiAbiTargeting(com.android.bundle.Targeting.MultiAbiTargeting) Test(org.junit.Test)

Aggregations

BuildApksResult (com.android.bundle.Commands.BuildApksResult)282 Test (org.junit.Test)276 ZipPath (com.android.tools.build.bundletool.model.ZipPath)234 Path (java.nio.file.Path)180 Variant (com.android.bundle.Commands.Variant)120 ZipFile (java.util.zip.ZipFile)109 AppBundle (com.android.tools.build.bundletool.model.AppBundle)96 AppBundleBuilder (com.android.tools.build.bundletool.testing.AppBundleBuilder)93 ImmutableSet (com.google.common.collect.ImmutableSet)88 FakeAdbServer (com.android.tools.build.bundletool.testing.FakeAdbServer)87 Theory (org.junit.experimental.theories.Theory)86 ApkSet (com.android.bundle.Commands.ApkSet)84 AdbServer (com.android.tools.build.bundletool.device.AdbServer)84 ApkDescription (com.android.bundle.Commands.ApkDescription)82 ApkSetUtils.extractFromApkSetFile (com.android.tools.build.bundletool.testing.ApkSetUtils.extractFromApkSetFile)78 ApkSetUtils.extractTocFromApkSetFile (com.android.tools.build.bundletool.testing.ApkSetUtils.extractTocFromApkSetFile)78 File (java.io.File)78 AssetSliceSet (com.android.bundle.Commands.AssetSliceSet)77 InvalidCommandException (com.android.tools.build.bundletool.model.exceptions.InvalidCommandException)77 IOException (java.io.IOException)76