use of com.android.tools.build.bundletool.testing.ResourcesTableFactory.MDPI in project bundletool by google.
the class ScreenDensityResourcesSplitterTest method lowestDensityConfigsPinnedToMaster.
@Test
public void lowestDensityConfigsPinnedToMaster() throws Exception {
BundleModule testModule = new BundleModuleBuilder("testModule").addFile("res/drawable-mdpi/image.jpg").addFile("res/drawable-hdpi/image.jpg").addFile("res/drawable-mdpi/image2.jpg").addFile("res/drawable-hdpi/image2.jpg").setResourceTable(new ResourceTableBuilder().addPackage("com.test.app").addDrawableResourceForMultipleDensities("image", ImmutableMap.of(/* mdpi */
160, "res/drawable-mdpi/image.jpg", /* hdpi */
240, "res/drawable-hdpi/image.jpg")).addDrawableResourceForMultipleDensities("image2", ImmutableMap.of(/* mdpi */
160, "res/drawable-mdpi/image2.jpg", /* hdpi */
240, "res/drawable-hdpi/image2.jpg")).build()).setManifest(androidManifest("com.test.app")).build();
Predicate<ResourceId> pinnedLowDensityResourcesPredicate = resourceId -> resourceId.getFullResourceId() == 0x7f010000;
ScreenDensityResourcesSplitter splitter = new ScreenDensityResourcesSplitter(BundleToolVersion.getCurrentVersion(), NO_RESOURCES_PINNED_TO_MASTER, pinnedLowDensityResourcesPredicate, /* pinLowestBucketOfStylesToMaster= */
false);
ImmutableCollection<ModuleSplit> densitySplits = splitter.split(ModuleSplit.forResources(testModule));
ModuleSplit masterSplit = densitySplits.stream().filter(split -> split.isMasterSplit()).collect(onlyElement());
assertThat(extractPaths(masterSplit.getEntries())).containsExactly("res/drawable-mdpi/image.jpg");
ImmutableList<ModuleSplit> configSplits = densitySplits.stream().filter(split -> !split.isMasterSplit()).collect(toImmutableList());
assertThat(configSplits).isNotEmpty();
for (ModuleSplit configSplit : configSplits) {
assertThat(extractPaths(configSplit.getEntries())).doesNotContain("res/drawable-mdpi/image.jpg");
}
}
use of com.android.tools.build.bundletool.testing.ResourcesTableFactory.MDPI in project bundletool by google.
the class BuildApksManagerTest method explicitMdpiPreferredOverDefault_enabledSince_0_9_1.
@Test
@Theory
public void explicitMdpiPreferredOverDefault_enabledSince_0_9_1(@FromDataPoints("bundleFeatureEnabled") boolean bundleFeatureEnabled) throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.addFile("res/drawable/image.jpg").addFile("res/drawable-mdpi/image.jpg").setManifest(androidManifest("com.test.app")).setResourceTable(new ResourceTableBuilder().addPackage("com.test.app").addDrawableResourceForMultipleDensities("image", ImmutableMap.of(/* default */
0, "res/drawable/image.jpg", /* mdpi */
160, "res/drawable-mdpi/image.jpg")).build())).setBundleConfig(BundleConfigBuilder.create().setVersion(bundleFeatureEnabled ? "0.9.1" : "0.9.0").build()).build();
TestComponent.useTestModule(this, createTestModuleBuilder().withAppBundle(appBundle).withOutputPath(outputFilePath).build());
buildApksManager.execute();
ZipFile apkSetFile = openZipFile(outputFilePath.toFile());
BuildApksResult result = extractTocFromApkSetFile(apkSetFile, outputDir);
ImmutableList<Variant> splitApkVariants = splitApkVariants(result);
ImmutableList<ApkDescription> mdpiSplits = apkDescriptions(splitApkVariants).stream().filter(apkDesc -> {
List<ScreenDensity> targetDensities = apkDesc.getTargeting().getScreenDensityTargeting().getValueList();
return targetDensities.stream().anyMatch(density -> density.getDensityAlias() == DensityAlias.MDPI) || targetDensities.stream().anyMatch(density -> density.getDensityDpi() == MDPI_VALUE);
}).collect(toImmutableList());
String fileToBePresent;
String fileToBeAbsent;
if (bundleFeatureEnabled) {
fileToBePresent = "res/drawable-mdpi/image.jpg";
fileToBeAbsent = "res/drawable/image.jpg";
} else {
fileToBeAbsent = "res/drawable-mdpi/image.jpg";
fileToBePresent = "res/drawable/image.jpg";
}
assertThat(mdpiSplits).isNotEmpty();
for (ApkDescription mdpiSplit : mdpiSplits) {
assertThat(filesInApk(mdpiSplit, apkSetFile)).contains(fileToBePresent);
assertThat(filesInApk(mdpiSplit, apkSetFile)).doesNotContain(fileToBeAbsent);
}
}
use of com.android.tools.build.bundletool.testing.ResourcesTableFactory.MDPI in project bundletool by google.
the class BuildApksManagerTest method buildApksCommand_universal_generatesSingleApkWithNoOptimizations.
@Test
public void buildApksCommand_universal_generatesSingleApkWithNoOptimizations() throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.addFile("lib/x86/libsome.so").addFile("lib/x86_64/libsome.so").setNativeConfig(nativeLibraries(targetedNativeDirectory("lib/x86", nativeDirectoryTargeting(X86)), targetedNativeDirectory("lib/x86_64", nativeDirectoryTargeting(X86_64)))).addFile("res/drawable-ldpi/image.jpg").addFile("res/drawable-mdpi/image.jpg").setResourceTable(new ResourceTableBuilder().addPackage("com.test.app").addFileResourceForMultipleConfigs("drawable", "image", ImmutableMap.of(LDPI, "res/drawable-ldpi/image.jpg", MDPI, "res/drawable-mdpi/image.jpg")).build()).setManifest(androidManifest("com.test.app"))).build();
TestComponent.useTestModule(this, createTestModuleBuilder().withAppBundle(appBundle).withOutputPath(outputFilePath).withApkBuildMode(UNIVERSAL).build());
buildApksManager.execute();
ZipFile apkSetFile = openZipFile(outputFilePath.toFile());
BuildApksResult result = extractTocFromApkSetFile(apkSetFile, outputDir);
// Should not shard by any dimension and generate single APK with default targeting.
assertThat(result.getVariantList()).hasSize(1);
assertThat(splitApkVariants(result)).isEmpty();
assertThat(standaloneApkVariants(result)).hasSize(1);
Variant universalVariant = standaloneApkVariants(result).get(0);
assertThat(universalVariant.getTargeting()).isEqualTo(UNRESTRICTED_VARIANT_TARGETING);
assertThat(apkDescriptions(universalVariant)).hasSize(1);
ApkDescription universalApk = apkDescriptions(universalVariant).get(0);
assertThat(universalApk.getTargeting()).isEqualToDefaultInstance();
// No ABI or density sharding.
File universalApkFile = extractFromApkSetFile(apkSetFile, universalApk.getPath(), outputDir);
try (ZipFile universalApkZipFile = new ZipFile(universalApkFile)) {
assertThat(filesUnderPath(universalApkZipFile, ZipPath.create("lib"))).containsExactly("lib/x86/libsome.so", "lib/x86_64/libsome.so");
// "res/xml/splits0.xml" is created by bundletool with list of generated splits.
assertThat(filesUnderPath(universalApkZipFile, ZipPath.create("res"))).containsExactly("res/drawable-ldpi/image.jpg", "res/drawable-mdpi/image.jpg", "res/xml/splits0.xml");
}
}
use of com.android.tools.build.bundletool.testing.ResourcesTableFactory.MDPI in project bundletool by google.
the class BuildApksManagerTest method pinningOfManifestReachableResources_disabled.
@Test
@Theory
public void pinningOfManifestReachableResources_disabled(@FromDataPoints("manifestReachableResourcesDisabledVersions") Version bundleVersion) throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.addFile("res/drawable-mdpi/manifest_image.jpg").addFile("res/drawable-hdpi/manifest_image.jpg").setManifest(androidManifest("com.test.app", withAppIcon(/* ID of "drawable/manifest_image" */
0x7f010000))).setResourceTable(new ResourceTableBuilder().addPackage("com.test.app").addDrawableResourceForMultipleDensities("manifest_image", ImmutableMap.of(/* mdpi */
160, "res/drawable-mdpi/manifest_image.jpg", /* hdpi */
240, "res/drawable-hdpi/manifest_image.jpg")).build())).setBundleConfig(BundleConfigBuilder.create().setVersion(bundleVersion.toString()).build()).build();
TestComponent.useTestModule(this, createTestModuleBuilder().withAppBundle(appBundle).withOutputPath(outputFilePath).build());
buildApksManager.execute();
ZipFile apkSetFile = openZipFile(outputFilePath.toFile());
BuildApksResult result = extractTocFromApkSetFile(apkSetFile, outputDir);
ImmutableList<Variant> splitApkVariants = splitApkVariants(result);
ImmutableList<ApkDescription> splitApks = apkDescriptions(splitApkVariants);
ImmutableList<ApkDescription> masterSplits = splitApks.stream().filter(apkDesc -> apkDesc.getSplitApkMetadata().getIsMasterSplit()).collect(toImmutableList());
assertThat(masterSplits).isNotEmpty();
for (ApkDescription masterSplit : masterSplits) {
assertThat(filesInApk(masterSplit, apkSetFile)).doesNotContain("res/drawable-mdpi/manifest_image.jpg");
}
ImmutableList<ApkDescription> densitySplits = splitApks.stream().filter(apkDesc -> apkDesc.getTargeting().hasScreenDensityTargeting()).collect(toImmutableList());
assertThat(densitySplits).isNotEmpty();
for (ApkDescription densitySplit : densitySplits) {
assertThat(filesInApk(densitySplit, apkSetFile)).containsAnyOf("res/drawable-mdpi/manifest_image.jpg", "res/drawable-hdpi/manifest_image.jpg");
}
}
Aggregations