use of com.android.bundle.Devices.DeviceSpec 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();
}
use of com.android.bundle.Devices.DeviceSpec in project bundletool by google.
the class ApkMatcherTest method splitAndStandaloneApks_variousDevices.
// Real-world complex selections.
@Test
public void splitAndStandaloneApks_variousDevices() {
ZipPath standaloneX86MdpiApk = ZipPath.create("standalone-x86.mdpi.apk");
ZipPath standaloneX86XxxhdpiApk = ZipPath.create("standalone-x86.xxxhdpi.apk");
ZipPath standaloneArmMdpiApk = ZipPath.create("standalone-arm.mdpi.apk");
ZipPath standaloneArmXxxhdpiApk = ZipPath.create("standalone-arm.xxxhdpi.apk");
ZipPath baseMasterSplitApk = ZipPath.create("base-master.apk");
ZipPath baseX86SplitApk = ZipPath.create("base-x86.apk");
ZipPath baseArmSplitApk = ZipPath.create("base-arm.apk");
ZipPath screenMdpiApk = ZipPath.create("screen-mdpi.apk");
ZipPath screenXxxhdpiApk = ZipPath.create("screen-xxxhdpi.apk");
ZipPath langsEnSplitApk = ZipPath.create("langs-en.apk");
ZipPath langsDeSplitApk = ZipPath.create("langs-de.apk");
BuildApksResult buildApksResult = buildApksResult(// Standalone X86 MDPI
standaloneVariant(mergeVariantTargeting(variantSdkTargeting(sdkVersionFrom(1), ImmutableSet.of(sdkVersionFrom(21))), variantAbiTargeting(X86, ImmutableSet.of(ARMEABI)), variantDensityTargeting(MDPI, ImmutableSet.of(XXXHDPI))), mergeApkTargeting(apkAbiTargeting(X86, ImmutableSet.of(ARMEABI)), apkDensityTargeting(MDPI, ImmutableSet.of(XXXHDPI))), standaloneX86MdpiApk), // Standalone X86 XXXHDI
standaloneVariant(mergeVariantTargeting(variantSdkTargeting(sdkVersionFrom(1), ImmutableSet.of(sdkVersionFrom(21))), variantAbiTargeting(X86, ImmutableSet.of(ARMEABI)), variantDensityTargeting(XXXHDPI, ImmutableSet.of(MDPI))), mergeApkTargeting(apkAbiTargeting(X86, ImmutableSet.of(ARMEABI)), apkDensityTargeting(XXXHDPI, ImmutableSet.of(MDPI))), standaloneX86XxxhdpiApk), // Standalone ARM MDPI
standaloneVariant(mergeVariantTargeting(variantSdkTargeting(sdkVersionFrom(1), ImmutableSet.of(sdkVersionFrom(21))), variantAbiTargeting(ARMEABI, ImmutableSet.of(X86)), variantDensityTargeting(MDPI, ImmutableSet.of(XXXHDPI))), mergeApkTargeting(apkAbiTargeting(ARMEABI, ImmutableSet.of(X86)), apkDensityTargeting(MDPI, ImmutableSet.of(XXXHDPI))), standaloneArmMdpiApk), // Standalone ARM XXXHDI
standaloneVariant(mergeVariantTargeting(variantSdkTargeting(sdkVersionFrom(1), ImmutableSet.of(sdkVersionFrom(21))), variantAbiTargeting(ARMEABI, ImmutableSet.of(X86)), variantDensityTargeting(XXXHDPI, ImmutableSet.of(MDPI))), mergeApkTargeting(apkAbiTargeting(ARMEABI, ImmutableSet.of(X86)), apkDensityTargeting(XXXHDPI, ImmutableSet.of(MDPI))), standaloneArmXxxhdpiApk), // Splits L+
splitApkVariant(variantSdkTargeting(sdkVersionFrom(21), ImmutableSet.of(sdkVersionFrom(1))), splitApkSet(/* moduleName= */
"base", splitApkDescription(ApkTargeting.getDefaultInstance(), baseMasterSplitApk), splitApkDescription(apkAbiTargeting(X86, ImmutableSet.of(ARMEABI)), baseX86SplitApk), splitApkDescription(apkAbiTargeting(ARMEABI, ImmutableSet.of(X86)), baseArmSplitApk)), splitApkSet(/* moduleName= */
"screen", splitApkDescription(apkDensityTargeting(MDPI, ImmutableSet.of(XXXHDPI)), screenMdpiApk), splitApkDescription(apkDensityTargeting(XXXHDPI, ImmutableSet.of(MDPI)), screenXxxhdpiApk)), splitApkSet(/* moduleName= */
"langs", splitApkDescription(apkLanguageTargeting("en"), langsEnSplitApk), splitApkDescription(apkLanguageTargeting("de"), langsDeSplitApk))));
DeviceSpec preLX86MdpiDevice = mergeSpecs(sdkVersion(19), abis("x86"), density(MDPI), locales("en"));
assertThat(new ApkMatcher(preLX86MdpiDevice).getMatchingApks(buildApksResult)).containsExactly(baseMatchedApk(standaloneX86MdpiApk));
DeviceSpec preLArmXxxdpiDevice = mergeSpecs(sdkVersion(19), abis("armeabi"), density(XXXHDPI), locales("en"));
assertThat(new ApkMatcher(preLArmXxxdpiDevice).getMatchingApks(buildApksResult)).containsExactly(baseMatchedApk(standaloneArmXxxhdpiApk));
DeviceSpec lX86MdpiEnDevice = mergeSpecs(sdkVersion(21), abis("x86"), density(MDPI), locales("en"));
assertThat(new ApkMatcher(lX86MdpiEnDevice).getMatchingApks(buildApksResult)).containsExactly(baseMatchedApk(baseMasterSplitApk), baseMatchedApk(baseX86SplitApk), matchedApk(screenMdpiApk, /* moduleName=*/
"screen", INSTALL_TIME), matchedApk(langsEnSplitApk, /* moduleName=*/
"langs", INSTALL_TIME));
// MIPS ABI is not supported by the app.
DeviceSpec preLMipsDevice = mergeSpecs(sdkVersion(19), abis("mips"), density(MDPI), locales("en"));
Throwable exception = assertThrows(IncompatibleDeviceException.class, () -> new ApkMatcher(preLMipsDevice).getMatchingApks(buildApksResult));
assertThat(exception).hasMessageThat().contains("The app doesn't support ABI architectures of the device. Device ABIs: [mips], " + "app ABIs: [x86, armeabi]");
}
use of com.android.bundle.Devices.DeviceSpec in project bundletool by google.
the class ApkMatcherTest method apkMatch_withModuleNameFiltering_splitApks_diamondModuleDependenciesGraph.
@Test
public void apkMatch_withModuleNameFiltering_splitApks_diamondModuleDependenciesGraph() {
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");
ZipPath feature3Apk = ZipPath.create("master-feature3.apk");
ZipPath feature4Apk = ZipPath.create("master-feature4.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)), splitApkSet(/* moduleName= */
"feature3", DeliveryType.ON_DEMAND, /* moduleDependencies= */
ImmutableList.of("feature1"), splitApkDescription(ApkTargeting.getDefaultInstance(), feature3Apk)), splitApkSet(/* moduleName= */
"feature4", DeliveryType.ON_DEMAND, /* moduleDependencies= */
ImmutableList.of("feature2", "feature3"), splitApkDescription(ApkTargeting.getDefaultInstance(), feature4Apk))));
// 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>> feature4ModuleOnly = Optional.of(ImmutableSet.of("feature4"));
assertThat(createMatcher(device, feature4ModuleOnly).getMatchingApks(buildApksResult)).containsExactly(baseMatchedApk(baseApk), matchedApk(feature1Apk, /* moduleName=*/
"feature1", ON_DEMAND), matchedApk(feature2Apk, /* moduleName=*/
"feature2", ON_DEMAND), matchedApk(feature3Apk, /* moduleName=*/
"feature3", ON_DEMAND), matchedApk(feature4Apk, /* moduleName=*/
"feature4", ON_DEMAND));
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));
}
use of com.android.bundle.Devices.DeviceSpec in project bundletool by google.
the class ApkMatcherTest method splitApk_conditionalModule_deviceNotEligible.
@Test
public void splitApk_conditionalModule_deviceNotEligible() {
DeviceSpec device = mergeSpecs(deviceWithSdk(21), deviceFeatures("reqGlEsVersion=0x30000"));
ZipPath baseApk = ZipPath.create("base-master.apk");
ZipPath feature1Apk = ZipPath.create("ar-master.apk");
ZipPath feature2Apk = ZipPath.create("opengl-master.apk");
ZipPath feature3Apk = ZipPath.create("high_end-master.apk");
BuildApksResult buildApksResult = buildApksResult(createVariant(variantSdkTargeting(21), splitApkSet(/* moduleName= */
"base", splitApkDescription(ApkTargeting.getDefaultInstance(), baseApk)), createConditionalApkSet(/* moduleName= */
"ar", mergeModuleTargeting(moduleFeatureTargeting("android.hardware.camera.ar"), moduleMinSdkVersionTargeting(24)), splitApkDescription(ApkTargeting.getDefaultInstance(), feature1Apk)), createConditionalApkSet(/* moduleName= */
"opengl", mergeModuleTargeting(moduleFeatureTargeting("android.hardware.opengles.version", 0x30001), moduleMinSdkVersionTargeting(21)), splitApkDescription(ApkTargeting.getDefaultInstance(), feature2Apk)), createConditionalApkSet(/* moduleName= */
"high_end", mergeModuleTargeting(moduleDeviceGroupsTargeting("highRam"), moduleMinSdkVersionTargeting(21)), splitApkDescription(ApkTargeting.getDefaultInstance(), feature3Apk))));
assertThat(new ApkMatcher(device).getMatchingApks(buildApksResult)).containsExactly(baseMatchedApk(baseApk));
}
use of com.android.bundle.Devices.DeviceSpec in project bundletool by google.
the class ApkMatcherTest method matchesModuleSplit_incompatibleDeviceThrows.
@Test
public void matchesModuleSplit_incompatibleDeviceThrows() {
// MIPS ABI is not supported by the split.
DeviceSpec mipsDevice = mergeSpecs(sdkVersion(21), abis("mips"), density(MDPI), locales("en"));
ModuleSplit moduleSplit = ModuleSplit.builder().setAndroidManifest(AndroidManifest.create(androidManifest("com.test.app"))).setEntries(ImmutableList.of()).setMasterSplit(false).setSplitType(SplitType.SPLIT).setModuleName(BundleModuleName.create("base")).setApkTargeting(apkAbiTargeting(AbiAlias.ARM64_V8A, ImmutableSet.of(AbiAlias.X86))).setVariantTargeting(variantSdkTargeting(21)).build();
Throwable exception = assertThrows(IncompatibleDeviceException.class, () -> new ApkMatcher(mipsDevice).matchesModuleSplitByTargeting(moduleSplit));
assertThat(exception).hasMessageThat().contains("The app doesn't support ABI architectures of the device. Device ABIs: [mips], " + "app ABIs: [arm64-v8a, x86]");
}
Aggregations