use of com.android.tools.build.bundletool.model.BundleModule in project bundletool by google.
the class ScreenDensityResourcesSplitterTest method densityBucket_neighbouringResources_edgeCase.
/**
* An edge case where xxxhdpi split capturing devices from 527dpi and above should capture 512dpi
* resources and above.
*
* <p>The 512dpi threshold depends on what other dpi values are available. Here, it's driven by
* the presence of 560dpi config value. A 527dpi device prefers 512dpi over 560dpi.
*
* <p>The 512dpi resource should also be present in the xxhdpi split. It targets all devices up to
* 526dpi.
*/
@Test
public void densityBucket_neighbouringResources_edgeCase() throws Exception {
ResourceTable table = resourceTable(pkg(USER_PACKAGE_OFFSET, "com.test.app", type(0x01, "drawable", entry(0x01, "image", fileReference("res/drawable-mdpi/image.png", MDPI), fileReference("res/drawable-512dpi/image.png", forDpi(512)), fileReference("res/drawable-560dpi/image.png", _560DPI), fileReference("res/drawable-xxxhdpi/image.png", XXXHDPI)))));
BundleModule module = new BundleModuleBuilder("base").addFile("res/drawable-mdpi/image.png").addFile("res/drawable-512dpi/image.png").addFile("res/drawable-560dpi/image.png").addFile("res/drawable-xxxhdpi/image.png").setResourceTable(table).setManifest(androidManifest("com.test.app")).build();
ScreenDensityResourcesSplitter splitter = new ScreenDensityResourcesSplitter(ImmutableSet.of(DensityAlias.XXHDPI, DensityAlias.XXXHDPI), BundleToolVersion.getCurrentVersion(), NO_RESOURCES_PINNED_TO_MASTER, NO_LOW_DENSITY_CONFIG_PINNED_TO_MASTER, /* pinLowestBucketOfStylesToMaster =*/
false);
ImmutableCollection<ModuleSplit> densitySplits = splitter.split(ModuleSplit.forResources(module));
ModuleSplit xxxhdpiSplit = findModuleSplitWithScreenDensityTargeting(densitySplits, ScreenDensity.newBuilder().setDensityAlias(DensityAlias.XXXHDPI).build());
assertThat(xxxhdpiSplit.getResourceTable()).isPresent();
ResourceTable xxxHdpiResourceTable = xxxhdpiSplit.getResourceTable().get();
assertThat(xxxHdpiResourceTable).containsResource("com.test.app:drawable/image").withConfigSize(3).withDensity(XXXHDPI_VALUE).withDensity(560).withDensity(512);
ModuleSplit xxhdpiSplit = findModuleSplitWithScreenDensityTargeting(densitySplits, ScreenDensity.newBuilder().setDensityAlias(DensityAlias.XXHDPI).build());
Truth8.assertThat(xxhdpiSplit.getResourceTable()).isPresent();
ResourceTable xxHdpiResourceTable = xxhdpiSplit.getResourceTable().get();
assertThat(xxHdpiResourceTable).containsResource("com.test.app:drawable/image").withConfigSize(2).withDensity(MDPI_VALUE).withDensity(512);
}
use of com.android.tools.build.bundletool.model.BundleModule in project bundletool by google.
the class ScreenDensityResourcesSplitterTest method preservesSourcePool.
@Test
public void preservesSourcePool() throws Exception {
StringPool sourcePool = StringPool.newBuilder().setData(ByteString.copyFrom(new byte[] { 'x' })).build();
ResourceTable table = new ResourceTableBuilder().addPackage("com.test.app").addDrawableResourceForMultipleDensities("image", ImmutableMap.of(MDPI_VALUE, "res/drawable-mdpi/image.jpg")).build().toBuilder().setSourcePool(sourcePool).build();
BundleModule testModule = new BundleModuleBuilder("testModule").addFile("res/drawable-mdpi/test.jpg").setResourceTable(table).setManifest(androidManifest("com.test.app")).build();
ImmutableCollection<ModuleSplit> densitySplits = splitter.split(ModuleSplit.forResources(testModule));
assertThat(densitySplits).hasSize(DEFAULT_DENSITY_BUCKETS.size() + 1);
for (ModuleSplit densitySplit : densitySplits) {
assertThat(densitySplit.getResourceTable()).isPresent();
assertThat(densitySplit.getResourceTable().get().getSourcePool()).isEqualTo(sourcePool);
}
}
use of com.android.tools.build.bundletool.model.BundleModule in project bundletool by google.
the class StandaloneApksGeneratorTest method shardByAbi_havingSingleAbi_producesOneApk.
@Test
public void shardByAbi_havingSingleAbi_producesOneApk() throws Exception {
BundleModule bundleModule = new BundleModuleBuilder("base").addFile("assets/file.txt").addFile("dex/classes.dex").addFile("lib/x86_64/libtest.so").addFile("res/drawable/image.jpg").addFile("res/drawable-mdpi/image.jpg").addFile("root/license.dat").setManifest(androidManifest("com.test.app")).setNativeConfig(nativeLibraries(targetedNativeDirectory("lib/x86_64", nativeDirectoryTargeting(X86_64)))).setResourceTable(new ResourceTableBuilder().addPackage("com.test.app").addDrawableResourceForMultipleDensities("image", ImmutableMap.of(DEFAULT_DENSITY_VALUE, "res/drawable/image.jpg", MDPI_VALUE, "res/drawable-mdpi/image.jpg")).build()).build();
ImmutableList<ModuleSplit> shards = standaloneApksGenerator.generateStandaloneApks(ImmutableList.of(bundleModule), standaloneApkOptimizations(OptimizationDimension.ABI));
assertThat(shards).hasSize(1);
ModuleSplit fatShard = shards.get(0);
assertThat(fatShard.getApkTargeting()).isEqualTo(apkAbiTargeting(AbiAlias.X86_64));
assertThat(fatShard.getVariantTargeting()).isEqualTo(mergeVariantTargeting(variantAbiTargeting(X86_64), VARIANT_TARGETING_WITH_SDK_1));
assertThat(fatShard.getSplitType()).isEqualTo(SplitType.STANDALONE);
assertThat(extractPaths(fatShard.getEntries())).containsExactly("assets/file.txt", "dex/classes.dex", "lib/x86_64/libtest.so", "res/drawable/image.jpg", "res/drawable-mdpi/image.jpg", "root/license.dat");
}
use of com.android.tools.build.bundletool.model.BundleModule in project bundletool by google.
the class StandaloneApksGeneratorTest method shardByAbiAndDensity_havingOneAbiAndSomeDensityResource_produceManyApks_transparency.
@Test
public void shardByAbiAndDensity_havingOneAbiAndSomeDensityResource_produceManyApks_transparency() throws Exception {
TestComponent.useTestModule(this, TestModule.builder().withBundleConfig(bundleConfigNodexmergestrategy).withBundleMetadata(BUNDLE_METADATA_WITH_TRANSPARENCY).build());
BundleModule bundleModule = new BundleModuleBuilder("base").addFile("assets/file.txt").addFile("dex/classes.dex").addFile("lib/x86/libtest.so").addFile("res/drawable-ldpi/image.jpg").addFile("res/drawable-hdpi/image.jpg").addFile("root/license.dat").setManifest(androidManifest("com.test.app")).setNativeConfig(nativeLibraries(targetedNativeDirectory("lib/x86", nativeDirectoryTargeting(X86)))).setResourceTable(new ResourceTableBuilder().addPackage("com.test.app").addDrawableResourceForMultipleDensities("image", ImmutableMap.of(LDPI_VALUE, "res/drawable-ldpi/image.jpg", HDPI_VALUE, "res/drawable-hdpi/image.jpg")).build()).build();
ImmutableList<ModuleSplit> shards = standaloneApksGenerator.generateStandaloneApks(ImmutableList.of(bundleModule), standaloneApkOptimizations(OptimizationDimension.ABI, OptimizationDimension.SCREEN_DENSITY));
// 7 shards: {x86} x {LDPI, MDPI, ..., XXXHDPI}.
assertThat(shards).hasSize(7);
assertThat(shards.stream().map(ModuleSplit::getSplitType).distinct().collect(toImmutableSet())).containsExactly(SplitType.STANDALONE);
for (ModuleSplit shard : shards) {
assertThat(extractPaths(shard.getEntries())).containsAtLeast("assets/file.txt", "dex/classes.dex", "lib/x86/libtest.so", "root/license.dat", "META-INF/code_transparency_signed.jwt");
}
}
use of com.android.tools.build.bundletool.model.BundleModule in project bundletool by google.
the class StandaloneApksGeneratorTest method manyModulesShardByNoDimension_producesFatApk.
@Test
public void manyModulesShardByNoDimension_producesFatApk() throws Exception {
BundleModule baseModule = new BundleModuleBuilder("base").addFile("lib/x86_64/libtest1.so").setNativeConfig(nativeLibraries(targetedNativeDirectory("lib/x86_64", nativeDirectoryTargeting(X86_64)))).addFile("res/drawable-ldpi/image1.jpg").setResourceTable(resourceTable(pkg(USER_PACKAGE_OFFSET, "com.test.app", type(0x01, "drawable", entry(0x01, "image1", fileReference("res/drawable-ldpi/image1.jpg", LDPI)))))).setManifest(androidManifest("com.test.app")).build();
BundleModule featureModule = new BundleModuleBuilder("feature").addFile("lib/x86_64/libtest2.so").setNativeConfig(nativeLibraries(targetedNativeDirectory("lib/x86_64", nativeDirectoryTargeting(X86_64)))).addFile("res/drawable-ldpi/image2.jpg").setResourceTable(resourceTable(pkg(USER_PACKAGE_OFFSET + 1, "com.test.app.split", type(0x01, "drawable", entry(0x01, "image2", fileReference("res/drawable-ldpi/image2.jpg", LDPI)))))).setManifest(androidManifestForFeature("com.test.app")).build();
ImmutableList<ModuleSplit> shards = standaloneApksGenerator.generateStandaloneApks(ImmutableList.of(baseModule, featureModule), NO_DIMENSIONS);
assertThat(shards).hasSize(1);
ModuleSplit fatApk = shards.get(0);
assertThat(extractPaths(fatApk.getEntries())).containsExactly("lib/x86_64/libtest1.so", "lib/x86_64/libtest2.so", "res/drawable-ldpi/image1.jpg", "res/drawable-ldpi/image2.jpg");
assertThat(fatApk.getResourceTable()).isPresent();
assertThat(fatApk.getResourceTable().get()).containsResource("com.test.app:drawable/image1").onlyWithConfigs(LDPI);
assertThat(fatApk.getResourceTable().get()).containsResource("com.test.app.split:drawable/image2").onlyWithConfigs(LDPI);
}
Aggregations