use of com.android.tools.build.bundletool.testing.BundleModuleBuilder 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.testing.BundleModuleBuilder 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.testing.BundleModuleBuilder 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.testing.BundleModuleBuilder 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);
}
use of com.android.tools.build.bundletool.testing.BundleModuleBuilder in project bundletool by google.
the class StandaloneApksGeneratorTest method shardByAbi_havingNoNativeTargeting_producesOneApk.
@Test
public void shardByAbi_havingNoNativeTargeting_producesOneApk() throws Exception {
BundleModule bundleModule = new BundleModuleBuilder("base").addFile("assets/file.txt").addFile("dex/classes.dex").addFile("lib/x86/libtest.so").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")).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()).isEqualToDefaultInstance();
assertThat(fatShard.getVariantTargeting()).isEqualTo(VARIANT_TARGETING_WITH_SDK_1);
assertThat(fatShard.getSplitType()).isEqualTo(SplitType.STANDALONE);
assertThat(extractPaths(fatShard.getEntries())).containsExactly("assets/file.txt", "dex/classes.dex", "lib/x86/libtest.so", "lib/x86_64/libtest.so", "res/drawable/image.jpg", "res/drawable-mdpi/image.jpg", "root/license.dat");
}
Aggregations