use of com.android.tools.build.bundletool.testing.ResourceTableBuilder 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.ResourceTableBuilder 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.ResourceTableBuilder 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.ResourceTableBuilder 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");
}
use of com.android.tools.build.bundletool.testing.ResourceTableBuilder in project bundletool by google.
the class StandaloneApksGeneratorTest method shardByAbi_havingManyAbis_producesManyApks_withTransparency.
@Test
public void shardByAbi_havingManyAbis_producesManyApks_withTransparency() 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/armeabi/libtest.so").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")).setNativeConfig(nativeLibraries(targetedNativeDirectory("lib/armeabi", nativeDirectoryTargeting(ARMEABI)), targetedNativeDirectory("lib/x86", nativeDirectoryTargeting(X86)), 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(3);
assertThat(shards.stream().map(ModuleSplit::getSplitType).distinct().collect(toImmutableSet())).containsExactly(SplitType.STANDALONE);
VariantTargeting armVariantTargeting = mergeVariantTargeting(variantAbiTargeting(ARMEABI, ImmutableSet.of(X86, X86_64)), VARIANT_TARGETING_WITH_SDK_1);
VariantTargeting x86VariantTargeting = mergeVariantTargeting(variantAbiTargeting(X86, ImmutableSet.of(ARMEABI, X86_64)), VARIANT_TARGETING_WITH_SDK_1);
VariantTargeting x64VariantTargeting = mergeVariantTargeting(variantAbiTargeting(X86_64, ImmutableSet.of(ARMEABI, X86)), VARIANT_TARGETING_WITH_SDK_1);
assertThat(shards.stream().map(ModuleSplit::getVariantTargeting).distinct().collect(toImmutableSet())).containsExactly(armVariantTargeting, x64VariantTargeting, x86VariantTargeting);
for (ModuleSplit shard : shards) {
assertThat(extractPaths(shard.getEntries())).containsAtLeast("assets/file.txt", "dex/classes.dex", "res/drawable/image.jpg", "res/drawable-mdpi/image.jpg", "root/license.dat", "META-INF/code_transparency_signed.jwt");
}
}
Aggregations