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));
}
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();
}
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));
}
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");
}
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);
}
Aggregations